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 2019/05/14 14:58:09 UTC
[incubator-tamaya-sandbox] 05/07: Implemented meta-config module
using hocon format. Moved hjson format to extensions. Adapted code to SPI
changes as needed.
This is an automated email from the ASF dual-hosted git repository.
anatole pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tamaya-sandbox.git
commit 3cb96a17c27775a19fdef65f02101699572b0843
Author: Anatole Tresch <at...@gmail.com>
AuthorDate: Fri May 10 19:56:48 2019 +0200
Implemented meta-config module using hocon format.
Moved hjson format to extensions.
Adapted code to SPI changes as needed.
---
.../tamaya/jsr382/JavaConfigAdapterFactory.java | 16 +-
.../JavaConfigDefaultPropertiesPropertySource.java | 3 +-
.../tamaya/jsr382/TamayaPropertySourceAdapter.java | 4 +-
.../tamaya/jsr382/JavaConfigAdapterTest.java | 2 +-
hjson/pom.xml | 88 --------
.../org/apache/tamaya/hjson/HJSONDataBuilder.java | 116 ----------
.../java/org/apache/tamaya/hjson/HJSONFormat.java | 61 ------
.../apache/tamaya/hjson/HJSONPropertySource.java | 130 -----------
.../PathBasedHJSONPropertySourceProvider.java | 58 -----
.../org.apache.tamaya.format.ConfigurationFormat | 19 --
.../hjson/CommonHJSONTestCaseCollection.java | 201 -----------------
.../org/apache/tamaya/hjson/HJSONFormatTest.java | 74 -------
.../tamaya/hjson/HJSONPropertySourceTest.java | 53 -----
.../org/apache/tamaya/hjson/HJSONVisitorTest.java | 92 --------
.../PathBasedHJSONPropertySourceProviderTest.java | 61 ------
.../META-INF/javaconfiguration.properties | 22 --
.../src/test/resources/configs/invalid/array.hjson | 21 --
.../resources/configs/invalid/empty-file.hjson | 18 --
.../configs/invalid/only-opening-bracket.hjson | 19 --
.../resources/configs/invalid/with-array.hjson | 27 ---
.../test/resources/configs/valid/cyrillic.hjson | 22 --
.../configs/valid/empty-object-config.hjson | 20 --
hjson/src/test/resources/configs/valid/kanji.hjson | 21 --
.../valid/simple-flat-string-only-config.hjson | 23 --
.../valid/simple-nested-string-only-config-1.hjson | 27 ---
.../valid/simple-nested-string-only-config-2.hjson | 26 ---
.../configs/valid/with-explicit-priority.hjson | 25 ---
metamodel/pom.xml | 5 +
.../org/apache/tamaya/metamodel/CachedFilter.java | 2 +-
.../tamaya/metamodel/EnabledPropertySource.java | 8 +-
.../org/apache/tamaya/metamodel/HideFilter.java | 2 +-
.../apache/tamaya/metamodel/ImmutableFilter.java | 4 +-
.../org/apache/tamaya/metamodel/MapFilter.java | 4 +-
.../org/apache/tamaya/metamodel/MaskFilter.java | 39 ++--
.../apache/tamaya/metamodel/MetaConfiguration.java | 48 ++--
.../org/apache/tamaya/metamodel/MetaContext.java | 244 ++++++++-------------
.../org/apache/tamaya/metamodel/SecuredFilter.java | 2 +-
.../ext/EnabledPropertySourceProvider.java | 19 +-
.../metamodel/ext/RefreshablePropertySource.java | 26 +--
.../ext/RefreshablePropertySourceProvider.java | 21 +-
.../metamodel/internal/ComponentConfigurator.java | 40 +---
.../metamodel/internal/ComponentFactory.java | 40 ++--
.../metamodel/internal/MetaContextReader.java | 189 ----------------
.../internal/PropertyConverterReader.java | 44 ++--
.../internal/PropertyFilterOrderingReader.java | 40 ++--
.../metamodel/internal/PropertyFilterReader.java | 59 ++---
.../internal/PropertySourceOrderingReader.java | 39 ++--
.../metamodel/internal/PropertySourceReader.java | 160 +++++++-------
.../internal/factories/CLIArgumentsFactory.java | 2 +-
...ry.java => ClasspathPropertySourceFactory.java} | 14 +-
...ctory.java => EnvironmentVariablesFactory.java} | 11 +-
.../factories/FilePropertySourceFactory.java | 8 +-
.../factories/ResourcePropertySourceFactory.java | 8 +-
.../ResourcePropertySourceProviderFactory.java | 9 +-
...tsFactory.java => SystemPropertiesFactory.java} | 11 +-
.../factories/URLPropertySourceFactory.java | 8 +-
.../metamodel/internal/resolver/JavaResolver.java | 29 +--
.../internal/resolver/PropertiesResolver.java | 9 +-
...SimpleResolver.java => ContextInitializer.java} | 13 +-
.../tamaya/metamodel/spi/ItemFactoryManager.java | 22 ++
.../metamodel/spi/MetaConfigurationReader.java | 8 +-
...apache.tamaya.metamodel.spi.ContextInitializer} | 2 -
.../org.apache.tamaya.metamodel.spi.ItemFactory | 3 +
...he.tamaya.metamodel.spi.MetaConfigurationReader | 1 -
.../tamaya/metamodel/ImmutableFilterTest.java | 36 ++-
.../apache/tamaya/metamodel/MaskFilterTest.java | 96 ++++++++
.../tamaya/metamodel/ext/IntegrationTest.java | 40 +---
.../factories/CLIArgumentsFactoryTest.java | 2 +-
.../internal/resolver/JavaResolverTest.java | 12 +-
.../metamodel/internal/resolver/LoggingReader.java | 76 -------
...st.xml => default-propertyconverters-test.conf} | 13 +-
...-test.xml => default-propertyfilters-test.conf} | 13 +-
...-test.xml => default-propertysources-test.conf} | 11 +-
...-propertyfilters-test.xml => empty-config.conf} | 9 +-
...test.xml => propertyconverter-config-test.conf} | 25 ++-
.../propertyconverter-config-test.xml | 32 ---
...pty-config.xml => propertyconverters-test.conf} | 12 +-
.../IntegrationTests/propertyconverters-test.xml | 30 ---
...es-test.xml => propertyfilter-config-test.conf} | 23 +-
.../propertyfilter-config-test.xml | 30 ---
...yfilters-test.xml => propertyfilters-test.conf} | 17 +-
.../propertysource-config-test.xml | 31 ---
...verters-test.xml => propertysources-test.hocon} | 25 +--
...he.tamaya.metamodel.spi.MetaConfigurationReader | 1 -
metamodel/src/test/resources/tamaya-config.conf | 124 +++++++++++
metamodel/src/test/resources/tamaya-config.xml | 23 +-
pom.xml | 1 -
.../tamaya/remote/BaseRemotePropertySource.java | 2 +-
.../ConfigValidationDocumentationReader.java | 2 +-
vertx/pom.xml | 2 +-
...Factory.java => ConfiguredVerticleFactory.java} | 7 +-
.../tamaya/vertx/TamayaConfigurationProducer.java | 3 +-
.../services/io.vertx.core.spi.VerticleFactory | 2 +-
.../apache/tamaya/vertx/ConfigVerticleTest.java | 1 -
94 files changed, 827 insertions(+), 2316 deletions(-)
diff --git a/configjsr/src/main/java/org/apache/tamaya/jsr382/JavaConfigAdapterFactory.java b/configjsr/src/main/java/org/apache/tamaya/jsr382/JavaConfigAdapterFactory.java
index fd5216f..9f095a9 100644
--- a/configjsr/src/main/java/org/apache/tamaya/jsr382/JavaConfigAdapterFactory.java
+++ b/configjsr/src/main/java/org/apache/tamaya/jsr382/JavaConfigAdapterFactory.java
@@ -213,11 +213,11 @@ public final class JavaConfigAdapterFactory {
}
/**
- * Converts the given Tamaya key, value map into a corresponding String based map, hereby
+ * Converts the given Tamaya key, value mapProperties into a corresponding String based mapProperties, hereby
* omitting all meta-entries.
*
- * @param properties the Tamaya key, value map, not null.
- * @return the corresponding String based map, never null.
+ * @param properties the Tamaya key, value mapProperties, not null.
+ * @return the corresponding String based mapProperties, never null.
*/
public static Map<String, String> toStringMap(Map<String, PropertyValue> properties) {
Map<String, String> valueMap = new HashMap<>(properties.size());
@@ -230,17 +230,17 @@ public final class JavaConfigAdapterFactory {
}
/**
- * Converts the given String based key, value map into a corresponding String,PropertyValue
- * based map.
+ * Converts the given String based key, value mapProperties into a corresponding String,PropertyValue
+ * based mapProperties.
*
- * @param properties the String based key, value map, not null.
+ * @param properties the String based key, value mapProperties, not null.
* @param source the source of the entries, not null.
- * @return the corresponding String,PropertyValue based map, never null.
+ * @return the corresponding String,PropertyValue based mapProperties, never null.
*/
public static Map<String, PropertyValue> toPropertyValueMap(Map<String, String> properties, String source) {
Map<String, PropertyValue> valueMap = new HashMap<>(properties.size());
for (Map.Entry<String, String> en : properties.entrySet()) {
- valueMap.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), source));
+ valueMap.put(en.getKey(), PropertyValue.createValue(en.getKey(), en.getValue()).setMeta("source", source));
}
return valueMap;
}
diff --git a/configjsr/src/main/java/org/apache/tamaya/jsr382/JavaConfigDefaultPropertiesPropertySource.java b/configjsr/src/main/java/org/apache/tamaya/jsr382/JavaConfigDefaultPropertiesPropertySource.java
index 0bf52f9..34d5b90 100644
--- a/configjsr/src/main/java/org/apache/tamaya/jsr382/JavaConfigDefaultPropertiesPropertySource.java
+++ b/configjsr/src/main/java/org/apache/tamaya/jsr382/JavaConfigDefaultPropertiesPropertySource.java
@@ -18,6 +18,7 @@
*/
package org.apache.tamaya.jsr382;
+import org.apache.tamaya.spi.ServiceContextManager;
import org.apache.tamaya.spisupport.propertysource.PropertiesResourcePropertySource;
@@ -27,7 +28,7 @@ import org.apache.tamaya.spisupport.propertysource.PropertiesResourcePropertySou
public class JavaConfigDefaultPropertiesPropertySource extends PropertiesResourcePropertySource {
public JavaConfigDefaultPropertiesPropertySource() {
- super("META-INF/javaconfig.properties", null);
+ super("META-INF/javaconfig.properties", ServiceContextManager.getDefaultClassLoader());
setDefaultOrdinal(100);
}
diff --git a/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceAdapter.java b/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceAdapter.java
index b61a605..e1e55b7 100644
--- a/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceAdapter.java
+++ b/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceAdapter.java
@@ -65,7 +65,7 @@ class TamayaPropertySourceAdapter implements PropertySource {
@Override
public PropertyValue get(String key) {
- return PropertyValue.of(key, delegate.getValue(key), getName());
+ return PropertyValue.createValue(key, delegate.getValue(key)).setMeta("source", getName());
}
@Override
@@ -76,7 +76,7 @@ class TamayaPropertySourceAdapter implements PropertySource {
private Map<String, PropertyValue> toValueMap(Map<String, String> properties) {
Map<String, PropertyValue> valueMap = new HashMap<>(properties.size());
for (Map.Entry<String, String> en : properties.entrySet()) {
- valueMap.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName()));
+ valueMap.put(en.getKey(), PropertyValue.createValue(en.getKey(), en.getValue()).setMeta("source", getName()));
}
return valueMap;
}
diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigAdapterTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigAdapterTest.java
index 15551cb..4a33c5d 100644
--- a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigAdapterTest.java
+++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigAdapterTest.java
@@ -163,7 +163,7 @@ public class JavaConfigAdapterTest {
@Test
public void toStringMap() throws Exception {
Map<String,PropertyValue> props = new HashMap<>();
- props.put("a", PropertyValue.of("a","b", "toStringMap"));
+ props.put("a", PropertyValue.createValue("a","b").setMeta("source", "toStringMap"));
Map<String, String> mpProps = JavaConfigAdapterFactory.toStringMap(props);
assertThat(mpProps).isNotNull().containsEntry("a", "b");
assertThat(props.keySet()).isEqualTo(mpProps.keySet());
diff --git a/hjson/pom.xml b/hjson/pom.xml
deleted file mode 100644
index 5d15dd4..0000000
--- a/hjson/pom.xml
+++ /dev/null
@@ -1,88 +0,0 @@
-<?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-sandbox</artifactId>
- <version>0.4-incubating-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
-
- <artifactId>tamaya-hjson_beta</artifactId>
- <name>Apache Tamaya Modules - HJSON Support</name>
- <packaging>jar</packaging>
-
- <inceptionYear>2018</inceptionYear>
-
- <description>
- This modules provides format support
- for using hjson files with Apache Tamaya.
- </description>
-
- <properties>
- <hjson.version>3.0.0</hjson.version>
- </properties>
-
- <dependencies>
- <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>
- <version>${project.parent.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-formats</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.hjson</groupId>
- <artifactId>hjson</artifactId>
- <version>${hjson.version}</version>
- </dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
- </dependency>
- </dependencies>
-
-</project>
diff --git a/hjson/src/main/java/org/apache/tamaya/hjson/HJSONDataBuilder.java b/hjson/src/main/java/org/apache/tamaya/hjson/HJSONDataBuilder.java
deleted file mode 100644
index 2cf4fa5..0000000
--- a/hjson/src/main/java/org/apache/tamaya/hjson/HJSONDataBuilder.java
+++ /dev/null
@@ -1,116 +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.hjson;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.ListValue;
-import org.apache.tamaya.spi.ObjectValue;
-import org.apache.tamaya.spi.PropertyValue;
-import org.hjson.JsonArray;
-import org.hjson.JsonObject;
-import org.hjson.JsonValue;
-
-import java.util.Objects;
-
-/**
- * Visitor implementation to read a HJSON asString input source.
- */
-class HJSONDataBuilder {
-
- private String resource;
- private PropertyValue data;
- private JsonValue root;
-
- HJSONDataBuilder(String resource, JsonValue root) {
- this.resource = Objects.requireNonNull(resource);
- this.root = root;
- }
-
- private void addJsonObject(JsonObject jsonObject, ObjectValue dataNode){
- jsonObject.forEach((m) -> {
- switch(m.getValue().getType()) {
- case BOOLEAN:
- dataNode.setValue(m.getName(), String.valueOf(m.getValue().asBoolean()));
- break;
- case NUMBER:
- dataNode.setValue(m.getName(), String.valueOf(m.getValue().asDouble()));
- break;
- case STRING:
- dataNode.setValue(m.getName(), m.getValue().asString());
- break;
- case NULL:
- dataNode.setValue(m.getName(), null);
- break;
- case OBJECT:
- ObjectValue oval = dataNode.setObject(m.getName());
- addJsonObject((JsonObject)m.getValue(), oval);
- break;
- case ARRAY:
- ListValue aval = dataNode.setList(m.getName());
- addArray((JsonArray)m.getValue(), aval);
- break;
- default:
- throw new ConfigException("Internal failure while processing JSON document.");
- }
- });
- }
-
- private void addArray(JsonArray array, ListValue dataNode) {
- array.forEach(val -> {
- switch(val.getType()) {
- case NULL:
- break;
- case BOOLEAN:
- dataNode.addValue(String.valueOf(val.asBoolean()));
- break;
- case NUMBER:
- case STRING:
- dataNode.addValue(val.toString());
- break;
- case OBJECT:
- ObjectValue oval = dataNode.addObject();
- addJsonObject((JsonObject)val, oval);
- break;
- case ARRAY:
- ListValue aval = dataNode.addList();
- addArray((JsonArray)val, aval);
- break;
- default:
- throw new ConfigException("Internal failure while processing JSON document.");
- }
- });
- }
-
- public PropertyValue build() {
- if (root instanceof JsonObject) {
- data = PropertyValue.createObject("");
- addJsonObject((JsonObject)root, (ObjectValue) data);
- } else if (root instanceof JsonArray) {
- JsonArray array = (JsonArray)root;
- data = PropertyValue.createList("");
- addArray(array, (ListValue)data);
- } else {
- throw new ConfigException("Unknown JsonType encountered: " + root.getClass().getName());
- }
- data.setMeta("resource", resource);
- data.setMeta("format", "json");
- return data;
- }
-
-}
diff --git a/hjson/src/main/java/org/apache/tamaya/hjson/HJSONFormat.java b/hjson/src/main/java/org/apache/tamaya/hjson/HJSONFormat.java
deleted file mode 100644
index 83c8a89..0000000
--- a/hjson/src/main/java/org/apache/tamaya/hjson/HJSONFormat.java
+++ /dev/null
@@ -1,61 +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.hjson;
-
-import org.apache.tamaya.format.ConfigurationData;
-import org.apache.tamaya.format.ConfigurationFormat;
-import org.hjson.JsonValue;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.util.Objects;
-
-/**
- * Implementation of the {@link ConfigurationFormat}
- * able to read configuration properties with comments represented in HJSON
- *
- * @see <a href="http://www.hjson.org">JSON format specification</a>
- */
-public class HJSONFormat implements ConfigurationFormat {
-
- @Override
- public String getName() {
- return "hjson";
- }
-
- @Override
- public boolean accepts(URL url) {
- return Objects.requireNonNull(url).getPath().endsWith(".hjson");
- }
-
- @Override
- public ConfigurationData readConfiguration(String resource, InputStream inputStream)
- throws IOException{
- try{
- JsonValue root = JsonValue.readHjson(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
- HJSONDataBuilder dataBuilder = new HJSONDataBuilder(resource, root);
- return new ConfigurationData(resource, this, dataBuilder.build());
- } catch(Exception e) {
- throw new IOException("Failed to read data from " + resource, e);
- }
- }
-}
diff --git a/hjson/src/main/java/org/apache/tamaya/hjson/HJSONPropertySource.java b/hjson/src/main/java/org/apache/tamaya/hjson/HJSONPropertySource.java
deleted file mode 100644
index c086e29..0000000
--- a/hjson/src/main/java/org/apache/tamaya/hjson/HJSONPropertySource.java
+++ /dev/null
@@ -1,130 +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.hjson;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.hjson.JsonValue;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import static java.lang.String.format;
-
-/**
- * Property source based on a HJSON file.
- */
-public class HJSONPropertySource implements PropertySource {
- /** The underlying resource. */
- private final URL urlResource;
- /** The values read. */
- private final Map<String, PropertyValue> values;
- /** The evaluated ordinal. */
- private int ordinal;
-
-
- /**
- * Constructor, hereby using 0 as the default ordinal.
- * @param resource the resource modelled as URL, not null.
- * @throws IOException if reading the resource fails.
- */
- public HJSONPropertySource(URL resource)throws IOException {
- this(resource, 0);
- }
-
- /**
- * Constructor.
- * @param resource the resource modelled as URL, not null.
- * @param defaultOrdinal the defaultOrdinal to be used.
- * @throws IOException if reading the resource fails.
- */
- public HJSONPropertySource(URL resource, int defaultOrdinal)throws IOException {
- urlResource = Objects.requireNonNull(resource);
- this.ordinal = defaultOrdinal; // may be overriden by read...
- this.values = readConfig(urlResource);
- if (this.values.containsKey(TAMAYA_ORDINAL)) {
- this.ordinal = Double.valueOf(this.values.get(TAMAYA_ORDINAL).getValue()).intValue();
- }
- }
-
-
- public int getOrdinal() {
- PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL);
- if(configuredOrdinal!=null){
- try{
- return Integer.parseInt(configuredOrdinal.getValue());
- } catch(Exception e){
- Logger.getLogger(getClass().getName()).log(Level.WARNING,
- "Configured Ordinal is not an int number: " + configuredOrdinal, e);
- }
- }
- return ordinal;
- }
-
- @Override
- public String getName() {
- return urlResource.toExternalForm();
- }
-
- @Override
- public PropertyValue get(String key) {
- return getProperties().get(key);
- }
-
- @Override
- public Map<String, PropertyValue> getProperties() {
-
- return Collections.unmodifiableMap(values);
- }
-
- /**
- * Reads the configuration.
- * @param urlResource soure of the configuration.
- * @return the configuration read from the given resource URL.
- * @throws ConfigException if resource URL cannot be read.
- * @throws IOException if reading the urlResource fails.
- */
- protected Map<String, PropertyValue> readConfig(URL urlResource) throws IOException{
- try (InputStream is = urlResource.openStream()) {
- JsonValue root = JsonValue.readHjson(new InputStreamReader(is, Charset.forName("UTF-8")));
- HJSONDataBuilder visitor = new HJSONDataBuilder(urlResource.toString(), root);
- Map<String, String> values = visitor.build().toMap();
- Map<String, PropertyValue> result = new HashMap<>();
- for(Map.Entry<String,String> en:values.entrySet()){
- result.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName()));
- }
- return result;
- }catch(IOException ioe){
- throw ioe;
- }catch (Exception t) {
- throw new IOException(format("Failed to read properties from %s", urlResource.toExternalForm()), t);
- }
- }
-
-}
diff --git a/hjson/src/main/java/org/apache/tamaya/hjson/PathBasedHJSONPropertySourceProvider.java b/hjson/src/main/java/org/apache/tamaya/hjson/PathBasedHJSONPropertySourceProvider.java
deleted file mode 100644
index f6fa174..0000000
--- a/hjson/src/main/java/org/apache/tamaya/hjson/PathBasedHJSONPropertySourceProvider.java
+++ /dev/null
@@ -1,58 +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.hjson;
-
-import org.apache.tamaya.resource.AbstractPathPropertySourceProvider;
-import org.apache.tamaya.spi.PropertySource;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Path based default provider for hjson formatted config files.
- */
-public class PathBasedHJSONPropertySourceProvider extends AbstractPathPropertySourceProvider{
-
- private static final Logger LOG = Logger.getLogger(PathBasedHJSONPropertySourceProvider.class.getName());
- private HJSONFormat jsonFormat = new HJSONFormat();
-
- public PathBasedHJSONPropertySourceProvider(String... paths) {
- super(paths);
- }
-
- @Override
- protected Collection<PropertySource> getPropertySources(URL url) {
- if(jsonFormat.accepts(url)){
- try {
- return Collections.singletonList(
- jsonFormat.readConfiguration(url.toString(), url.openStream()).toPropertySource());
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Failed to read yaml file: " +url, e);
- }
- }
- return Collections.emptyList();
- }
-
-}
-
-
diff --git a/hjson/src/main/resources/META-INF/services/org.apache.tamaya.format.ConfigurationFormat b/hjson/src/main/resources/META-INF/services/org.apache.tamaya.format.ConfigurationFormat
deleted file mode 100644
index e8f9bd4..0000000
--- a/hjson/src/main/resources/META-INF/services/org.apache.tamaya.format.ConfigurationFormat
+++ /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.hjson.HJSONFormat
\ No newline at end of file
diff --git a/hjson/src/test/java/org/apache/tamaya/hjson/CommonHJSONTestCaseCollection.java b/hjson/src/test/java/org/apache/tamaya/hjson/CommonHJSONTestCaseCollection.java
deleted file mode 100644
index 94fe4f8..0000000
--- a/hjson/src/test/java/org/apache/tamaya/hjson/CommonHJSONTestCaseCollection.java
+++ /dev/null
@@ -1,201 +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.hjson;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spisupport.PropertySourceComparator;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.net.URL;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Class with a collection of common test cases each JSON processing
- * class must be able to pass.
- */
-public abstract class CommonHJSONTestCaseCollection {
-
- abstract PropertySource getPropertiesFrom(URL source) throws Exception;
-
- @Test
- public void canReadNonLatinCharacters() throws Exception {
- URL configURL = CommonHJSONTestCaseCollection.class
- .getResource("/configs/valid/cyrillic.hjson");
-
- assertThat(configURL).isNotNull();
-
- PropertySource propertySource = getPropertiesFrom(configURL);
-
- assertThat(propertySource.get("name")).isNotNull();
- assertThat(propertySource.get("name").getValue()).isEqualTo("\u041e\u043b\u0438\u0432\u0435\u0440");
- assertThat(propertySource.get("\u0444\u0430\u043c\u0438\u043b\u0438\u044f")).isNotNull();
- assertThat(propertySource.get("\u0444\u0430\u043c\u0438\u043b\u0438\u044f").getValue()).isEqualTo("Fischer");
- }
-
- @Test
- public void canReadUnicodeCharacters() throws Exception {
- URL configURL = CommonHJSONTestCaseCollection.class
- .getResource("/configs/valid/kanji.hjson");
-
- assertThat(configURL).isNotNull();
-
- PropertySource propertySource = getPropertiesFrom(configURL);
-
- assertThat(propertySource.get("onamae")).isNotNull();
- // 霊屋 = Tamaya
- assertThat(propertySource.get("onamae").getValue()).isEqualTo("\u970a\u5c4b");
- }
-
- @Test
- public void canReadNestedStringOnlyJSONConfigFile2() throws Exception {
- URL configURL = CommonHJSONTestCaseCollection.class
- .getResource("/configs/valid/simple-nested-string-only-config-1.hjson");
-
- assertThat(configURL).isNotNull();
-
- PropertySource properties = getPropertiesFrom(configURL);
-
- System.out.println("simple-nested-string-only-config-1.json -> " + properties.getProperties().values());
-
- assertThat(properties.getProperties().keySet().size()).isGreaterThanOrEqualTo(5);
-
- PropertyValue keyB = properties.get("b");
- PropertyValue keyDO = properties.get("d.o");
- PropertyValue keyDP = properties.get("d.p");
-
- assertThat(keyB).isNotNull();
- assertThat(keyB.getValue()).isEqualTo("B");
- assertThat(keyDO).isNotNull();
- assertThat(keyDO.getValue()).isEqualTo("O");
- assertThat(keyDP).isNotNull();
- assertThat(keyDP.getValue()).isEqualTo("P");
- }
-
- @Test
- public void canReadNestedStringOnlyJSONConfigFileWithObjectInTheMiddle()
- throws Exception {
- URL configURL = CommonHJSONTestCaseCollection.class
- .getResource("/configs/valid/simple-nested-string-only-config-2.hjson");
-
- assertThat(configURL).isNotNull();
-
- PropertySource properties = getPropertiesFrom(configURL);
-
- assertThat(properties.getProperties().keySet().size()).isGreaterThanOrEqualTo(4);
-
- PropertyValue keyA = properties.get("a");
- PropertyValue keyDO = properties.get("b.o");
- PropertyValue keyDP = properties.get("b.p");
- PropertyValue keyC = properties.get("c");
-
- assertThat(keyA).isNotNull();
- assertThat(keyA.getValue()).isEqualTo("A");
- assertThat(keyC).isNotNull();
- assertThat(keyC.getValue()).isEqualTo("C");
- assertThat(keyDO).isNotNull();
- assertThat(keyDO.getValue()).isEqualTo("O");
- assertThat(keyDP).isNotNull();
- assertThat(keyDP.getValue()).isEqualTo("P");
- }
-
- @Test
- public void canHandleIllegalJSONFileWhichContainsAnArray() throws Exception {
- URL configURL = CommonHJSONTestCaseCollection.class.getResource("/configs/invalid/with-array.hjson");
-
- assertThat(configURL).isNotNull();
-
- getPropertiesFrom(configURL).getProperties();
- }
-
- @Test(expected = IOException.class)
- public void canHandleIllegalJSONFileConsistingOfOneOpeningBracket() throws Exception {
- URL configURL = CommonHJSONTestCaseCollection.class.getResource("/configs/invalid/only-opening-bracket.hjson");
-
- assertThat(configURL).isNotNull();
-
- getPropertiesFrom(configURL).getProperties();
- }
-
- @Test
- public void canHandleIllegalJSONFileWhichIsEmpty() throws Exception {
- URL configURL = CommonHJSONTestCaseCollection.class.getResource("/configs/invalid/empty-file.hjson");
-
- assertThat(configURL).isNotNull();
-
- getPropertiesFrom(configURL).getProperties();
- }
-
- @Test
- public void priorityInConfigFileOverwriteExplicitlyGivenPriority() throws Exception {
- URL configURL = CommonHJSONTestCaseCollection.class.getResource("/configs/valid/with-explicit-priority.hjson");
-
- assertThat(configURL).isNotNull();
-
- PropertySource properties = getPropertiesFrom(configURL);
-
- assertThat(PropertySourceComparator.getOrdinal(properties)).isEqualTo(16784);
- }
-
- @Test
- public void canReadFlatStringOnlyJSONConfigFile() throws Exception {
- URL configURL = CommonHJSONTestCaseCollection.class.getResource("/configs/valid/simple-flat-string-only-config.hjson");
-
- assertThat(configURL).isNotNull();
-
- PropertySource properties = getPropertiesFrom(configURL);
-
- assertThat(properties.getProperties()).hasSize(3);
-
- PropertyValue keyA = properties.get("a");
- PropertyValue keyB = properties.get("b");
- PropertyValue keyC = properties.get("c");
-
- assertThat(keyA).isNotNull();
- assertThat(keyA.getValue()).isEqualTo("A");
- assertThat(keyB).isNotNull();
- assertThat(keyB.getValue()).isEqualTo("B");
- assertThat(keyC).isNotNull();
- assertThat(keyC.getValue()).isEqualTo("C");
- }
-
- @Test
- public void emptyJSONFileResultsInConfigException() throws Exception {
- URL configURL = CommonHJSONTestCaseCollection.class.getResource("/configs/invalid/empty-file.hjson");
-
- assertThat(configURL).isNotNull();
-
- PropertySource properties = getPropertiesFrom(configURL);
-
- properties.getProperties();
- }
-
- @Test
- public void canHandleEmptyJSONObject() throws Exception {
- URL configURL = CommonHJSONTestCaseCollection.class.getResource("/configs/valid/empty-object-config.hjson");
-
- assertThat(configURL).isNotNull();
-
- PropertySource properties = getPropertiesFrom(configURL);
-
- assertThat(properties.getProperties().keySet().size()).isGreaterThanOrEqualTo(0);
- }
-}
diff --git a/hjson/src/test/java/org/apache/tamaya/hjson/HJSONFormatTest.java b/hjson/src/test/java/org/apache/tamaya/hjson/HJSONFormatTest.java
deleted file mode 100644
index f008aad..0000000
--- a/hjson/src/test/java/org/apache/tamaya/hjson/HJSONFormatTest.java
+++ /dev/null
@@ -1,74 +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.hjson;
-
-
-import org.apache.tamaya.format.ConfigurationData;
-import org.apache.tamaya.format.MappedConfigurationDataPropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Test;
-
-import java.io.InputStream;
-import java.net.URL;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class HJSONFormatTest extends CommonHJSONTestCaseCollection {
- private final HJSONFormat format = new HJSONFormat();
-
- @Test(expected = NullPointerException.class)
- public void acceptsNeedsNonNullParameter() throws Exception {
- format.accepts(null);
- }
-
- @Test
- public void aNonJSONFileBasedURLIsNotAccepted() throws Exception {
- URL url = new URL("file:///etc/service/conf.conf");
-
- assertThat(format.accepts(url)).isFalse();
- }
-
- @Test
- public void aJSONFileBasedURLIsAccepted() throws Exception {
- URL url = new URL("file:///etc/service/conf.hjson");
-
- assertThat(format.accepts(url)).isTrue();
- }
-
- @Test
- public void aHTTPBasedURLIsNotAccepted() throws Exception {
- URL url = new URL("http://nowhere.somewhere/conf.hjson");
- assertThat(format.accepts(url)).isTrue();
- }
-
- @Test
- public void aFTPBasedURLIsNotAccepted() throws Exception {
- URL url = new URL("ftp://nowhere.somewhere/a/b/c/d/conf.hjson");
-
- assertThat(format.accepts(url)).isTrue();
- }
-
- @Override
- PropertySource getPropertiesFrom(URL source) throws Exception {
- try (InputStream is = source.openStream()) {
- ConfigurationData data = format.readConfiguration(source.toString(), is);
- return new MappedConfigurationDataPropertySource(data);
- }
- }
-}
diff --git a/hjson/src/test/java/org/apache/tamaya/hjson/HJSONPropertySourceTest.java b/hjson/src/test/java/org/apache/tamaya/hjson/HJSONPropertySourceTest.java
deleted file mode 100644
index 52dacd3..0000000
--- a/hjson/src/test/java/org/apache/tamaya/hjson/HJSONPropertySourceTest.java
+++ /dev/null
@@ -1,53 +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.hjson;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Test;
-
-import java.net.URL;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class HJSONPropertySourceTest extends CommonHJSONTestCaseCollection {
-
- @Test
- public void tamayaOrdinalKeywordIsNotPropagatedAsNormalProperty() throws Exception {
- URL configURL = HJSONPropertySourceTest.class.getResource("/configs/valid/with-explicit-priority.hjson");
-
- assertThat(configURL).isNotNull();
-
- HJSONPropertySource source = new HJSONPropertySource(configURL, 4);
- assertThat(source.getOrdinal()).isEqualTo(16784);
- }
-
- @Test
- public void testAcceptJsonArrays() throws Exception {
- URL configURL = HJSONPropertySourceTest.class.getResource("/configs/invalid/array.hjson");
-
- assertThat(configURL).isNotNull();
-
- new HJSONPropertySource(configURL);
- }
-
- @Override
- PropertySource getPropertiesFrom(URL source) throws Exception {
- return new HJSONPropertySource(source);
- }
-}
diff --git a/hjson/src/test/java/org/apache/tamaya/hjson/HJSONVisitorTest.java b/hjson/src/test/java/org/apache/tamaya/hjson/HJSONVisitorTest.java
deleted file mode 100644
index 53c7429..0000000
--- a/hjson/src/test/java/org/apache/tamaya/hjson/HJSONVisitorTest.java
+++ /dev/null
@@ -1,92 +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.hjson;
-
-import org.apache.tamaya.spi.ObjectValue;
-import org.apache.tamaya.spi.PropertyValue;
-import org.hjson.JsonArray;
-import org.hjson.JsonObject;
-import org.hjson.JsonValue;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class HJSONVisitorTest {
-
- @Test
- public void ensureJSONisParsedProperlyWithDifferentValueTypesFilteringOutEmptyValues() {
- JsonObject startNode = new JsonObject().//
- add("key.sub", "createValue").//
- add("anotherKey", true).//
- add("notAnotherKey", false).//
- add("number", 4711).//
- add("null", JsonValue.NULL).//
- add("empty", "");
- HJSONDataBuilder visitor = new HJSONDataBuilder("Test:ensureJSONisParsedProperlyWithDifferentValueTypesFilteringOutEmptyValues", startNode);
-
- PropertyValue data = visitor.build();
- assertThat(data).isNotNull();
-
- ObjectValue ov = data.toObjectValue();
- assertThat(ov.getValues()).hasSize(6);
- assertThat(data.toMap()).containsKeys("key.sub", "anotherKey", "notAnotherKey", "number", "null")
- .containsEntry("key.sub", "createValue")
- .containsEntry("null", null)
- .containsEntry("anotherKey", "true")
- .doesNotContainEntry("empty", null);
- }
-
- @Test
- public void parsingWorksOnEmptyObject() {
- JsonObject startNode = new JsonObject();
-
- Map<String, String> targetStore = new HashMap<>();
-
- HJSONDataBuilder visitor = new HJSONDataBuilder("Test:parsingWorksOnEmptyObject", startNode);
- PropertyValue data = visitor.build();
- assertThat(data).isNotNull();
- assertThat(data.isLeaf()).isFalse();
- }
-
- @Test
- public void arrayInObject() {
- JsonObject startNode = new JsonObject().
- add("arrayKey", new JsonArray());
- HJSONDataBuilder visitor = new HJSONDataBuilder("Test:array", startNode);
- PropertyValue data = visitor.build();
- assertThat(data).isNotNull();
- System.out.println(data.asString());
- }
-
- @Test
- public void array() {
- JsonArray startNode = new JsonArray().
- add(new JsonObject().add("k1", 1).add("k2", 2)).
- add(new JsonObject().add("k1", 1).add("k2", 2)).
- add(new JsonArray().add(new JsonObject().add("k31", "v31").add("k32", false)));
- HJSONDataBuilder visitor = new HJSONDataBuilder("Test:array", startNode);
- PropertyValue data = visitor.build();
- assertThat(data).isNotNull();
- System.out.println(data.asString());
- }
-
-}
diff --git a/hjson/src/test/java/org/apache/tamaya/hjson/PathBasedHJSONPropertySourceProviderTest.java b/hjson/src/test/java/org/apache/tamaya/hjson/PathBasedHJSONPropertySourceProviderTest.java
deleted file mode 100644
index 8008f8c..0000000
--- a/hjson/src/test/java/org/apache/tamaya/hjson/PathBasedHJSONPropertySourceProviderTest.java
+++ /dev/null
@@ -1,61 +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.hjson;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Tests for {@link PathBasedHJSONPropertySourceProvider}.
- */
-public class PathBasedHJSONPropertySourceProviderTest {
-
- @Test
- public void getPropertySources() {
- PathBasedHJSONPropertySourceProvider provider = new PathBasedHJSONPropertySourceProvider(
- "configs/valid/*.hjson"
- );
- assertThat(provider.getPropertySources()).isNotNull().hasSize(7);
- }
-
- @Test
- public void getPropertySources_one() {
- PathBasedHJSONPropertySourceProvider provider = new PathBasedHJSONPropertySourceProvider(
- "configs/valid/cyril*.hjson"
- );
- assertThat(provider.getPropertySources()).isNotNull().hasSize(1);
- }
-
- @Test
- public void getPropertySources_two() {
- PathBasedHJSONPropertySourceProvider provider = new PathBasedHJSONPropertySourceProvider(
- "configs/valid/simple-*.hjson"
- );
- assertThat(provider.getPropertySources()).isNotNull().hasSize(3);
- }
-
- @Test
- public void getPropertySources_none() {
- PathBasedHJSONPropertySourceProvider provider = new PathBasedHJSONPropertySourceProvider(
- "configs/valid/foo*.hjson", "configs/valid/*.HJSON"
- );
- assertThat(provider.getPropertySources()).isNotNull().isEmpty();
- }
-}
diff --git a/hjson/src/test/resources/META-INF/javaconfiguration.properties b/hjson/src/test/resources/META-INF/javaconfiguration.properties
deleted file mode 100644
index e66e448..0000000
--- a/hjson/src/test/resources/META-INF/javaconfiguration.properties
+++ /dev/null
@@ -1,22 +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.
-
-# The space before the actual date is intended!
-dateTimeValue= 2010-08-08T14:00:15.5+10:00
-dateTimeZoneValueA=UTC
-dateTimeZoneValueB=+01:00
-periodValueA=P1Y1M1W1DT1H1M1S
diff --git a/hjson/src/test/resources/configs/invalid/array.hjson b/hjson/src/test/resources/configs/invalid/array.hjson
deleted file mode 100644
index 0c2058a..0000000
--- a/hjson/src/test/resources/configs/invalid/array.hjson
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy 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.
-*/
-[
-
-]
\ No newline at end of file
diff --git a/hjson/src/test/resources/configs/invalid/empty-file.hjson b/hjson/src/test/resources/configs/invalid/empty-file.hjson
deleted file mode 100644
index f396085..0000000
--- a/hjson/src/test/resources/configs/invalid/empty-file.hjson
+++ /dev/null
@@ -1,18 +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.
-*/
\ No newline at end of file
diff --git a/hjson/src/test/resources/configs/invalid/only-opening-bracket.hjson b/hjson/src/test/resources/configs/invalid/only-opening-bracket.hjson
deleted file mode 100644
index b936f69..0000000
--- a/hjson/src/test/resources/configs/invalid/only-opening-bracket.hjson
+++ /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 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.
-*/
-{
\ No newline at end of file
diff --git a/hjson/src/test/resources/configs/invalid/with-array.hjson b/hjson/src/test/resources/configs/invalid/with-array.hjson
deleted file mode 100644
index e623e49..0000000
--- a/hjson/src/test/resources/configs/invalid/with-array.hjson
+++ /dev/null
@@ -1,27 +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.
-*/
-{
- "a" : "A",
- "b" : {
- "c" : "C",
- "d" : [
- "1", "2"
- ]
- }
-}
\ No newline at end of file
diff --git a/hjson/src/test/resources/configs/valid/cyrillic.hjson b/hjson/src/test/resources/configs/valid/cyrillic.hjson
deleted file mode 100644
index da86e77..0000000
--- a/hjson/src/test/resources/configs/valid/cyrillic.hjson
+++ /dev/null
@@ -1,22 +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.
-*/
-{
- name : "Оливер",
- фамилия : "Fischer"
-}
\ No newline at end of file
diff --git a/hjson/src/test/resources/configs/valid/empty-object-config.hjson b/hjson/src/test/resources/configs/valid/empty-object-config.hjson
deleted file mode 100644
index 103c28d..0000000
--- a/hjson/src/test/resources/configs/valid/empty-object-config.hjson
+++ /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 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.
-*/
-{
-}
\ No newline at end of file
diff --git a/hjson/src/test/resources/configs/valid/kanji.hjson b/hjson/src/test/resources/configs/valid/kanji.hjson
deleted file mode 100644
index 1d1c54a..0000000
--- a/hjson/src/test/resources/configs/valid/kanji.hjson
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy 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.
-*/
-{
- onamae : 霊屋
-}
\ No newline at end of file
diff --git a/hjson/src/test/resources/configs/valid/simple-flat-string-only-config.hjson b/hjson/src/test/resources/configs/valid/simple-flat-string-only-config.hjson
deleted file mode 100644
index d961b62..0000000
--- a/hjson/src/test/resources/configs/valid/simple-flat-string-only-config.hjson
+++ /dev/null
@@ -1,23 +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.
-*/
-{
- a : A
- b : B
- c : C
-}
\ No newline at end of file
diff --git a/hjson/src/test/resources/configs/valid/simple-nested-string-only-config-1.hjson b/hjson/src/test/resources/configs/valid/simple-nested-string-only-config-1.hjson
deleted file mode 100644
index 622cf29..0000000
--- a/hjson/src/test/resources/configs/valid/simple-nested-string-only-config-1.hjson
+++ /dev/null
@@ -1,27 +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.
-*/
-{
- a: A
- b: B
- c: C
- d: {
- o: O
- p: P
- }
-}
diff --git a/hjson/src/test/resources/configs/valid/simple-nested-string-only-config-2.hjson b/hjson/src/test/resources/configs/valid/simple-nested-string-only-config-2.hjson
deleted file mode 100644
index a43aee6..0000000
--- a/hjson/src/test/resources/configs/valid/simple-nested-string-only-config-2.hjson
+++ /dev/null
@@ -1,26 +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.
-*/
-{
- a : A
- b : {
- o : O
- p : P
- }
- c : C
-}
diff --git a/hjson/src/test/resources/configs/valid/with-explicit-priority.hjson b/hjson/src/test/resources/configs/valid/with-explicit-priority.hjson
deleted file mode 100644
index aa0d8e1..0000000
--- a/hjson/src/test/resources/configs/valid/with-explicit-priority.hjson
+++ /dev/null
@@ -1,25 +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.
-*/
-{
- /*
- some useful comment here
- */
- tamaya.ordinal : 16784
- a : A // another comment
-}
diff --git a/metamodel/pom.xml b/metamodel/pom.xml
index 14662d0..e3ae3d1 100644
--- a/metamodel/pom.xml
+++ b/metamodel/pom.xml
@@ -51,6 +51,11 @@
<version>${project.parent.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-hocon</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-spisupport</artifactId>
<version>${project.parent.version}</version>
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
index 618cacf..73f1388 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
@@ -45,7 +45,7 @@ public class CachedFilter implements PropertyFilter{
public static final class CachedFilterFactory implements ItemFactory<PropertyFilter> {
@Override
public String getName() {
- return "Cached";
+ return "cached";
}
@Override
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySource.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySource.java
index a88a799..497ecb0 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySource.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySource.java
@@ -42,15 +42,15 @@ public final class EnabledPropertySource
private boolean enabled;
private static final JavaResolver RESOLVER = new JavaResolver();
- public EnabledPropertySource(PropertySource wrapped, Map<String,String> context, String expression) {
+ public EnabledPropertySource(PropertySource wrapped, String expression) {
this.enabledExpression = Objects.requireNonNull(expression);
this.wrapped = Objects.requireNonNull(wrapped);
- this.enabled = calculateEnabled(context);
+ this.enabled = calculateEnabled();
}
- protected boolean calculateEnabled(Map<String, String> context) {
+ protected boolean calculateEnabled() {
try {
- return Boolean.TRUE.equals(RESOLVER.evaluate(enabledExpression, context));
+ return Boolean.TRUE.equals(RESOLVER.evaluate(enabledExpression));
} catch (Exception e) {
LOG.severe("Invalid Boolean expression: '"
+enabledExpression+"': " + e + ", property source will be disabled: " +
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java
index b100906..c8d68c2 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java
@@ -40,7 +40,7 @@ public class HideFilter implements PropertyFilter{
public static final class HideFilterFactory implements ItemFactory<PropertyFilter> {
@Override
public String getName() {
- return "Hide";
+ return "hide";
}
@Override
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java
index 0a2acad..7089586 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java
@@ -39,7 +39,7 @@ public class ImmutableFilter implements PropertyFilter{
public static final class ImmutableFilterFactory implements ItemFactory<PropertyFilter> {
@Override
public String getName() {
- return "Immutable";
+ return "immutable";
}
@Override
@@ -58,7 +58,7 @@ public class ImmutableFilter implements PropertyFilter{
@Override
public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
String key = value.getKey();
- if(!context.isSinglePropertyScoped()) {
+ if(context!=null && !context.isSinglePropertyScoped()) {
key = value.getKey() + "_all";
}
PropertyValue val = map.get(key);
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java
index 9bf7d15..e85bbac 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java
@@ -42,7 +42,7 @@ public class MapFilter implements PropertyFilter{
public static final class MapFilterFactory implements ItemFactory<PropertyFilter> {
@Override
public String getName() {
- return "Map";
+ return "mapped";
}
@Override
@@ -95,7 +95,7 @@ public class MapFilter implements PropertyFilter{
if(cutoff !=null){
if(value.getKey().startsWith(cutoff)){
key = key.substring(cutoff.length());
- value.setKey(key);
+ value = value.setKey(key);
}
}
if(target!=null){
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java
index f59f5d2..b92be5d 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java
@@ -38,7 +38,9 @@ public class MaskFilter implements PropertyFilter{
private String matches;
private List<String> roles = new ArrayList<>();
private String mask = "*****";
- private TargetPolicy policy = TargetPolicy.ALL;
+ private boolean filterSingleValues;
+ private boolean filterAllValues = true;
+
/**
* Factory for configuring immutable property filter.
@@ -46,7 +48,7 @@ public class MaskFilter implements PropertyFilter{
public static final class MaskFilterFactory implements ItemFactory<PropertyFilter> {
@Override
public String getName() {
- return "Mask";
+ return "mask";
}
@Override
@@ -99,24 +101,29 @@ public class MaskFilter implements PropertyFilter{
return this;
}
- public TargetPolicy getPolicy() {
- return policy;
+ public boolean isFilterSingleValues() {
+ return filterSingleValues;
+ }
+
+ public boolean isFilterAllValues() {
+ return filterAllValues;
}
- public MaskFilter setPolicy(TargetPolicy policy) {
- this.policy = policy;
+ public MaskFilter setFilterSingleValues(boolean filterSingleValues) {
+ this.filterSingleValues = filterSingleValues;
return this;
}
- public MaskFilter setPolicy(String policy) {
- return setPolicy(TargetPolicy.valueOf(policy));
+ public MaskFilter setFilterAllValues(boolean filterAllValues) {
+ this.filterAllValues = filterAllValues;
+ return this;
}
@Override
public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
if(matches !=null){
if(value.getKey().matches(matches)){
- return null;
+ return PropertyValue.createValue(value.getKey(), mask);
}
}
return value;
@@ -124,17 +131,13 @@ public class MaskFilter implements PropertyFilter{
@Override
public String toString() {
- return "HideFilter{" +
+ return "MaskFilter{" +
"matches='" + matches + '\'' +
+ ", mask='" + mask + '\'' +
+ ", roles='" + roles + '\'' +
+ ", filterAllValues='" + filterAllValues + '\'' +
+ ", filterSingleValues='" + filterSingleValues + '\'' +
'}';
}
- /**
- * The target policy for masking properties.
- */
- private enum TargetPolicy {
- ALL,
- SINGLEVALUE,
- MULTIVALUE
- }
}
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaConfiguration.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaConfiguration.java
index 5b54812..ae0ccd6 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaConfiguration.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaConfiguration.java
@@ -19,30 +19,28 @@
package org.apache.tamaya.metamodel;
import java.io.File;
-import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.List;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.ConfigurationFormat;
+import org.apache.tamaya.format.ConfigurationFormats;
import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
import org.apache.tamaya.spi.ConfigurationBuilder;
import org.apache.tamaya.spi.ServiceContextManager;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
/**
* Accessor singleton for accessing/loading getMeta-configuration.
*/
public final class MetaConfiguration {
- private static final String CONFIG_RESOURCE = "tamaya-config.xml";
+ private static final String CONFIG_RESOURCE = "tamaya-config.conf";
private static final Logger LOG = Logger.getLogger(MetaConfiguration.class.getName());
@@ -56,7 +54,7 @@ public final class MetaConfiguration {
* and applies it as default configuration using {@link Configuration#current()} (Configuration)}.
*/
public static void configure(){
- LOG.info("TAMAYA: Checking for getMeta-configuration...");
+ LOG.info("TAMAYA: Checking for meta-configuration...");
URL configFile = getDefaultMetaConfig();
if(configFile==null){
LOG.warning("TAMAYA: No " + CONFIG_RESOURCE + " found, using defaults.");
@@ -108,22 +106,28 @@ public final class MetaConfiguration {
*/
public static ConfigurationBuilder createConfigBuilder(URL metaConfig){
URL configFile = Objects.requireNonNull(metaConfig);
- LOG.info("TAMAYA: Loading tamaya-config.xml...");
- Document document = null;
- try {
- document = DocumentBuilderFactory.newInstance()
- .newDocumentBuilder().parse(configFile.openStream());
- ConfigurationBuilder builder = Configuration.createConfigurationBuilder();
- for(MetaConfigurationReader reader: ServiceContextManager.getServiceContext().getServices(
- MetaConfigurationReader.class
- )){
- LOG.fine("TAMAYA: Executing MetaConfig-Reader: " + reader.getClass().getName() + "...");
- reader.read(document, builder);
+ LOG.info("TAMAYA: Loading "+metaConfig.toString()+"...");
+ List<ConfigurationFormat> formats = ConfigurationFormats.getInstance().getFormats(metaConfig);
+ if(formats.isEmpty()){
+ throw new IllegalStateException("Please install a matching ConfigurationFormat for the meta configuration: " + metaConfig);
+ }
+ for(ConfigurationFormat format:formats) {
+ try {
+ ConfigurationData data = format.readConfiguration(configFile.toString(),
+ configFile.openStream());
+ ConfigurationBuilder builder = Configuration.createConfigurationBuilder();
+ for (MetaConfigurationReader reader : ServiceContextManager.getServiceContext().getServices(
+ MetaConfigurationReader.class
+ )) {
+ LOG.fine("TAMAYA: Executing MetaConfig-Reader: " + reader.getClass().getName() + "...");
+ reader.read(data, builder);
+ }
+ return builder;
+ } catch (Exception e) {
+ throw new ConfigException("Cannot read meta-config from " + metaConfig, e);
}
- return builder;
- } catch (SAXException | IOException | ParserConfigurationException e) {
- throw new ConfigException("Cannot read getMeta-config deom " + metaConfig, e);
}
+ throw new IllegalStateException("No ConfigurationFormat matched the meta configuration: " + metaConfig);
}
/**
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
index 56e1540..3ada4d6 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
@@ -18,83 +18,73 @@
*/
package org.apache.tamaya.metamodel;
+import org.apache.tamaya.metamodel.spi.ContextInitializer;
+import org.apache.tamaya.spi.ServiceContextManager;
+
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
+import java.util.logging.Logger;
/**
- * Class managing a configuration system's getMeta-context. This
+ * Class managing a configuration system's meta-context. This
* context is used by the configuration system to evaluate the
* right properties, e.g. by defining the current stage or labels
- * that apply to the current configuration. Hereby contexts are
- * <ul>
- * <li>stackable into a context hierarchy, see {@link #combineWith(MetaContext, MetaContext...)}</li>
- * <li>providing key/values only valid for a certain time (assigned a TTL), see {@link #setProperty(String, String, int, TimeUnit)},
- * {@link #setProperties(Map, long, TimeUnit)}</li>
- * </ul>
- * Additionally there is special support for thread related contexts, see {@link #getThreadInstance()}.
- * Finally there is also one special globally shared context instance, see {@link #getInstance()}.
+ * that apply to the current configuration.
*/
public final class MetaContext {
- private static final ThreadLocal<MetaContext> THREAD_CONTEXT = new ThreadLocal<MetaContext>(){
- @Override
- protected MetaContext initialValue() {
- return new MetaContext();
- }
- };
+ private static final Logger LOG = Logger.getLogger(MetaContext.class.getName());
- private final Map<String,Value> properties = new ConcurrentHashMap<>();
+ private static final MetaContext INSTANCE = new MetaContext();
- private static final MetaContext GLOBAL_CONTEXT = new MetaContext();
+ private final Map<String,Object> properties = new ConcurrentHashMap<>();
/** The unique id of this context. */
- private MetaContext(){
- setProperty("_id", UUID.randomUUID().toString());
+ public MetaContext(){
+
+ setStringProperty("_id", UUID.randomUUID().toString());
+ initialize();
}
/**
- * Get the context's id.
- * @return the context's id
+ * Get the current metacontext.
+ * @return the meta-context, never null.
*/
- public String getId() {
- return getProperty("_id", "N/A");
+ public static MetaContext getInstance() {
+ return INSTANCE;
}
-
/**
- * Access the global context. There might be other contexts used in the system, which also
- * may delegate to the global context.
- * @return the context instance, never null.
+ * Get the context's id.
+ * @return the context's id
*/
- public static MetaContext getInstance(){
- return GLOBAL_CONTEXT;
+ public String getId() {
+ return getStringProperty("_id").orElse("N/A");
}
/**
- * Access the thread-based context. If no such context
- * exists a new one will be created.
- * @param reinit if true, clear's the thread's context.
- * @return the corresponding context, never null.
+ * Reads and applies the {@link ContextInitializer}s using the default classloader..
*/
- public static MetaContext getThreadInstance(boolean reinit){
- MetaContext threadContext = THREAD_CONTEXT.get();
- if(reinit){
- threadContext.properties.clear();
- }
- return threadContext;
+ public void initialize(){
+ initialize(ServiceContextManager.getDefaultClassLoader());
}
/**
- * Access the current context, which actually is the current context, combined with the thread based
- * context (overriding).
- * @return the corresponding context, never null.
+ * Reads and applies the {@link ContextInitializer}s for the given class loader.
+ * @param classLoader the target classloader, never null.
*/
- public MetaContext getThreadInstance(){
- return getThreadInstance(false);
+ public void initialize(ClassLoader classLoader){
+ for(ContextInitializer initializer: ServiceContextManager.getServiceContext(classLoader)
+ .getServices(ContextInitializer.class)){
+ try{
+ initializer.initializeContext(this);
+ }catch(Exception e){
+ LOG.log(Level.WARNING, "ContextInitializer failed: " + initializer.getClass().getName(), e);
+ }
+ }
}
-
/**
* Combine this context with the other contexts given.
* @param baseContext the base context with which the other contexts will be merged
@@ -115,27 +105,36 @@ public final class MetaContext {
* @param key the key, not null
* @return the createValue, or null.
*/
- public String getProperty(String key){
- return getProperty(key, null);
+ public Optional<String> getStringProperty(String key){
+ return getProperty(key, String.class);
}
/**
* Access the given context property.
- * @param key the key, not the default createValue.
- * @param defaultValue the default createValue to be returned, if no createValue is defined, or the
- * stored createValue's TTL has been reached.
- * @return the createValue, default createValue or null.
+ * @param key the key, not null
+ * @return the createValue, or null.
*/
- public String getProperty(String key, String defaultValue){
- Value value = this.properties.get(key);
- if(value==null){
- return defaultValue;
- }
- if(!value.isValid()){
- this.properties.remove(key);
- return null;
- }
- return value.value;
+ public Optional<Boolean> getBooleanProperty(String key){
+ return getProperty(key, Boolean.class);
+ }
+
+ /**
+ * Access the given context property.
+ * @param key the key, not null
+ * @return the createValue, or null.
+ */
+ public Optional<Number> getNumberProperty(String key){
+ return getProperty(key, Number.class);
+ }
+
+ /**
+ * Access the given context property.
+ * @param key the key, not null
+ * @return the createValue, or null.
+ */
+ public <T> Optional<T> getProperty(String key, Class<T> type){
+ T value = (T)this.properties.get(key);
+ return Optional.ofNullable(value);
}
/**
@@ -144,77 +143,65 @@ public final class MetaContext {
* @param value the createValue, not null.
* @return the previous createValue, or null.
*/
- public String setProperty(String key, String value){
- return setProperty(key, value, 0, TimeUnit.MILLISECONDS);
+ public String setStringProperty(String key, String value){
+ return setProperty(key, String.class, value);
}
/**
* Sets the given context property.
* @param key the key, not null.
* @param value the createValue, not null.
- * @param ttl the time to live. Zero or less than zero means, no timeout.
- * @param unit the target time unit.
* @return the previous createValue, or null.
*/
- public String setProperty(String key, String value, int ttl, TimeUnit unit){
- Value previous = this.properties.put(key, new Value(key, value, ttl));
- if(previous!=null && previous.isValid()){
- return previous.value;
- }
- return null;
+ public Boolean setBooleanProperty(String key, Boolean value){
+ return setProperty(key, Boolean.class, value);
}
/**
- * Sets the given property unless there is already a createValue defined.
+ * Sets the given context property.
* @param key the key, not null.
* @param value the createValue, not null.
+ * @return the previous createValue, or null.
*/
- public void setPropertyIfAbsent(String key, String value){
- setPropertyIfAbsent(key, value, 0, TimeUnit.MILLISECONDS);
+ public Number setNumberProperty(String key, Number value){
+ return setProperty(key, Number.class, value);
}
/**
- * Sets the given property unless there is already a createValue defined.
+ * Sets the given context property.
* @param key the key, not null.
* @param value the createValue, not null.
- * @param ttl the time to live. Zero or less than zero means, no timeout.
- * @param unit the target time unit.
+ * @return the previous createValue, or null.
*/
- public void setPropertyIfAbsent(String key, String value, long ttl, TimeUnit unit){
- Value prev = this.properties.get(key);
- if(prev==null){
- this.properties.put(key, new Value(key, value, unit.toMillis(ttl)));
+ public <T> T setProperty(String key, Class<T> type, T value){
+ T previous = (T)this.properties.put(key, Objects.requireNonNull(value));
+ if(previous!=null){
+ return previous;
}
+ return null;
}
/**
- * Adds all properties given, overriding any existing properties.
- * @param properties the properties, not null.
- */
- public void setProperties(Map<String,String> properties){
- setProperties(properties, 0L, TimeUnit.MILLISECONDS);
- }
-
- /**
- * Adds all properties given, overriding any existing properties.
- * @param properties the properties, not null.
- * @param ttl the time to live. Zero or less than zero means, no timeout.
- * @param unit the target time unit.
+ * Sets the given property unless there is already a createValue defined.
+ * @param key the key, not null.
+ * @param value the createValue, not null.
*/
- public void setProperties(Map<String,String> properties, long ttl, TimeUnit unit){
- for(Map.Entry<String, String> en:properties.entrySet()) {
- this.properties.put(
- en.getKey().toString(),
- new Value(en.getKey().toString(), en.getValue().toString(), unit.toMillis(ttl)));
+ public <T> T setPropertyIfAbsent(String key, Class<T> type, T value){
+ T prev = (T)this.properties.get(key);
+ if(prev==null){
+ this.properties.put(key, value);
+ return prev;
}
+ return null;
}
+
/**
* Checks if all the given properties are present.
* @param keys the keys to check, not null.
* @return true, if all the given keys are existing.
*/
- public boolean checkProperties(String... keys){
+ public boolean checkPropertiesArePresent(String... keys){
for(String key:keys) {
if (getProperty(key, null) == null) {
return false;
@@ -227,17 +214,8 @@ public final class MetaContext {
* Access all the current context properties.
* @return the properties, never null.
*/
- public Map<String,String> getProperties(){
- Map<String,String> map = new HashMap<>();
- for(Map.Entry<String,Value> en:properties.entrySet()) {
- Value val = en.getValue();
- if(val.isValid()){
- map.put(en.getKey(), val.value);
- }else{
- this.properties.remove(en.getKey());
- }
- }
- return Collections.unmodifiableMap(map);
+ public Map<String,Object> getProperties(){
+ return Collections.unmodifiableMap(properties);
}
@Override
@@ -264,51 +242,7 @@ public final class MetaContext {
return "MetaContext{" +
"id=" + getId() +
", properties=" + properties +
- ", global=" + (this == MetaContext.GLOBAL_CONTEXT) +
'}';
}
- /**
- * A class representing a meta value.
- */
- private static final class Value{
- private String key;
- private String value;
- private long validUntil;
-
- Value(String key, String value, long ttl){
- this.key = Objects.requireNonNull(key);
- this.value = Objects.requireNonNull(value);
- if(ttl>0) {
- this.validUntil = System.currentTimeMillis() + ttl;
- }
- }
-
- /** Method to check if a createValue is still valid. */
- boolean isValid(){
- return this.validUntil<=0 || this.validUntil>=System.currentTimeMillis();
- }
-
- /** Method that invalidates a createValue. */
- void invalidate(){
- this.validUntil = 0;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof Value)) {
- return false;
- }
- Value value = (Value) o;
- return Objects.equals(value, this);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(value);
- }
- }
}
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java
index 7c80db0..e49b170 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java
@@ -50,7 +50,7 @@ public class SecuredFilter implements PropertyFilter{
public static final class SecuredFilterFactory implements ItemFactory<PropertyFilter> {
@Override
public String getName() {
- return "Secured";
+ return "secured";
}
@Override
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/EnabledPropertySourceProvider.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/EnabledPropertySourceProvider.java
index ca7c46c..21d20a5 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/EnabledPropertySourceProvider.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/EnabledPropertySourceProvider.java
@@ -29,6 +29,8 @@ import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import org.apache.tamaya.metamodel.Enabled;
+import org.apache.tamaya.metamodel.MetaContext;
+import org.apache.tamaya.metamodel.Refreshable;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
@@ -37,20 +39,19 @@ import org.apache.tamaya.spi.PropertySourceProvider;
* {@code enabled} expression.
*/
public final class EnabledPropertySourceProvider
- implements PropertySourceProvider, Enabled {
+ implements PropertySourceProvider, Enabled, Refreshable {
private static final Logger LOG = Logger.getLogger(EnabledPropertySourceProvider.class.getName());
private String enabledExpression;
private PropertySourceProvider wrapped;
private boolean enabled;
- public EnabledPropertySourceProvider(PropertySourceProvider wrapped, Map<String,String> context, String expression) {
+ public EnabledPropertySourceProvider(PropertySourceProvider wrapped, String expression) {
this.enabledExpression = Objects.requireNonNull(expression);
this.wrapped = Objects.requireNonNull(wrapped);
- this.enabled = calculateEnabled(context);
}
- protected boolean calculateEnabled(Map<String, String> context) {
+ protected boolean calculateEnabled() {
try {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("nashorn");
@@ -58,7 +59,7 @@ public final class EnabledPropertySourceProvider
engine = manager.getEngineByName("rhino");
}
// init script engine
- for(Map.Entry<String,String> entry: context.entrySet()) {
+ for(Map.Entry<String,Object> entry: MetaContext.getInstance().getProperties().entrySet()) {
engine.put(entry.getKey(), entry.getValue());
}
Object o = engine.eval(enabledExpression);
@@ -105,10 +106,16 @@ public final class EnabledPropertySourceProvider
}
@Override
+ public void refresh() {
+ calculateEnabled();
+ }
+
+ @Override
public String toString() {
- return "DynamicPropertySourceProvider{" +
+ return "EnabledPropertySourceProvider{" +
"\n enabled=" + enabledExpression +
"\n wrapped=" + wrapped +
'}';
}
+
}
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/RefreshablePropertySource.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/RefreshablePropertySource.java
index eb2b8d3..1826bf3 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/RefreshablePropertySource.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/RefreshablePropertySource.java
@@ -19,12 +19,10 @@
package org.apache.tamaya.metamodel.ext;
import org.apache.tamaya.metamodel.Refreshable;
-import org.apache.tamaya.metamodel.internal.ComponentConfigurator;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spisupport.PropertySourceComparator;
-import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@@ -45,39 +43,27 @@ public final class RefreshablePropertySource
implements PropertySource, Refreshable {
private static final Logger LOG = Logger.getLogger(RefreshablePropertySource.class.getName());
- private Map<String,String> metaConfig;
private PropertySource wrapped;
private AtomicLong nextRefresh = new AtomicLong();
private AtomicLong refreshPeriod = new AtomicLong();
- private RefreshablePropertySource(Map<String,String> metaConfig, PropertySource wrapped) {
- this.metaConfig = Objects.requireNonNull(metaConfig);
- this.wrapped = Objects.requireNonNull(wrapped);
+ private RefreshablePropertySource(PropertySource propertySource) {
+ this.wrapped = Objects.requireNonNull(propertySource);
}
/**
* Makes a property source refreshable. If the given property source is already an instance of
* RefreshablePropertySource, the property source is returned.
- * @param metaConfig the configuration parameters to be applied when a new PropertySource is created, not null.
* @param propertySource the property source, not null.
* @return a new instance, not null.
*/
- public static RefreshablePropertySource of(Map<String,String> metaConfig, PropertySource propertySource) {
+ public static RefreshablePropertySource of(PropertySource propertySource) {
if(propertySource instanceof RefreshablePropertySource){
return (RefreshablePropertySource)propertySource;
}
- return new RefreshablePropertySource(metaConfig, propertySource);
+ return new RefreshablePropertySource(propertySource);
}
- /**
- * Makes a property source refreshable. If the given property source is already an instance of
- * RefreshablePropertySource, the property source is returned.
- * @param propertySource the property source, not null.
- * @return a new instance, not null.
- */
- public static RefreshablePropertySource of(PropertySource propertySource) {
- return of(Collections.<String, String>emptyMap(), propertySource);
- }
/**
* Checks if the property source should autorefresh, if so {@link #refresh()} is called.
@@ -108,8 +94,7 @@ public final class RefreshablePropertySource
if(this.wrapped instanceof Refreshable){
((Refreshable) this.wrapped).refresh();
}else {
- this.wrapped = this.wrapped.getClass().newInstance();
- ComponentConfigurator.configure(this.wrapped, metaConfig);
+ this.wrapped = this.wrapped.getClass().getConstructor().newInstance();
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Failed to reload/refresh PropertySource: " +
@@ -145,7 +130,6 @@ public final class RefreshablePropertySource
@Override
public String toString() {
return "RefreshablePropertySource{" +
- "\n metaConfig=" + metaConfig +
"\n wrapped=" + wrapped +
'}';
}
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/RefreshablePropertySourceProvider.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/RefreshablePropertySourceProvider.java
index e4e23cf..2ff2f70 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/RefreshablePropertySourceProvider.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/ext/RefreshablePropertySourceProvider.java
@@ -18,14 +18,14 @@
*/
package org.apache.tamaya.metamodel.ext;
+import org.apache.tamaya.metamodel.MetaContext;
import org.apache.tamaya.metamodel.Refreshable;
import org.apache.tamaya.metamodel.internal.ComponentConfigurator;
+import org.apache.tamaya.spi.ObjectValue;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -42,11 +42,13 @@ public final class RefreshablePropertySourceProvider
implements PropertySourceProvider, Refreshable {
private static final Logger LOG = Logger.getLogger(RefreshablePropertySourceProvider.class.getName());
- private Map<String,String> metaConfig;
+ private ObjectValue nodeConfig;
+ private MetaContext metaConfig;
private PropertySourceProvider wrapped;
private Collection<PropertySource> propertSources;
- private RefreshablePropertySourceProvider(Map<String,String> metaConfig, PropertySourceProvider wrapped) {
+ private RefreshablePropertySourceProvider(ObjectValue nodeConfig, MetaContext metaConfig, PropertySourceProvider wrapped) {
+ this.nodeConfig = nodeConfig;
this.metaConfig = Objects.requireNonNull(metaConfig);
this.wrapped = Objects.requireNonNull(wrapped);
this.propertSources = Objects.requireNonNull(wrapped.getPropertySources());
@@ -55,15 +57,16 @@ public final class RefreshablePropertySourceProvider
/**
* Makes a property source provider refreshable. If the given property source provider is already an instance of
* RefreshablePropertySourceProvider, the property source provider is returned unchanged.
- * @param metaConfig the configuration parameters to be applied when a new PropertySourceProvider is created, not null.
+ * @param nodeConfig the pased node configuration.
+ * @param metaContext the configuration parameters to be applied when a new PropertySourceProvider is created, not null.
* @param provider the property source provider, not null.
* @return a new instance, not null.
*/
- public static RefreshablePropertySourceProvider of(Map<String,String> metaConfig, PropertySourceProvider provider) {
+ public static RefreshablePropertySourceProvider of(ObjectValue nodeConfig, MetaContext metaContext, PropertySourceProvider provider) {
if(provider instanceof RefreshablePropertySourceProvider){
return (RefreshablePropertySourceProvider)provider;
}
- return new RefreshablePropertySourceProvider(metaConfig, provider);
+ return new RefreshablePropertySourceProvider(nodeConfig, metaContext, provider);
}
/**
@@ -73,7 +76,7 @@ public final class RefreshablePropertySourceProvider
* @return a new instance, not null.
*/
public static RefreshablePropertySourceProvider of(PropertySourceProvider provider) {
- return of(Collections.<String, String>emptyMap(), provider);
+ return of(null, new MetaContext(), provider);
}
@Override
@@ -88,7 +91,7 @@ public final class RefreshablePropertySourceProvider
((Refreshable) this.wrapped).refresh();
}else {
this.wrapped = this.wrapped.getClass().newInstance();
- ComponentConfigurator.configure(this.wrapped, metaConfig);
+ ComponentConfigurator.configure(this.wrapped, nodeConfig.toMap());
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Failed to refresh PropertySourceProvider: " +
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java
index 7b8ed6d..92a4e0d 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java
@@ -18,10 +18,6 @@
*/
package org.apache.tamaya.metamodel.internal;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -43,19 +39,12 @@ public final class ComponentConfigurator<T> {
/**
* Configures the given instance with whatever is defined in the current child values.
* @param instance the instance to be configured, not null.
- * @param node the value containing any configuration child values, not null.
- */
- public static void configure(Object instance, Node node) {
- Map<String,String> params = extractParameters(node);
- configure(instance, params);
- }
-
- /**
- * Configures the given instance with whatever is defined in the current child values.
- * @param instance the instance to be configured, not null.
- * @param params the value containing any configuration child values, not null.
+ * @param params the params containing any configuration child values, not null.
*/
public static void configure(Object instance, Map<String,String> params) {
+ if(params==null){
+ return;
+ }
LOG.finest("Configuring instance: " + instance + " with " + params);
for(Map.Entry<String,String> en:params.entrySet()){
applyParam(instance, en.getKey(), en.getValue());
@@ -199,25 +188,4 @@ public final class ComponentConfigurator<T> {
}
}
- public static Map<String, String> extractParameters(Node node) {
- Map<String,String> params = new HashMap<>();
- NamedNodeMap attributes = node.getAttributes();
- for(int c=0;c<attributes.getLength();c++) {
- Node pn = attributes.item(c);
- String key = pn.getNodeName();
- String value = pn.getNodeValue();
- params.put(key, value);
- }
- NodeList entryNodes = node.getChildNodes();
- for(int c=0;c<entryNodes.getLength();c++) {
- Node filterNode = entryNodes.item(c);
- if(filterNode.getNodeType()==Node.ELEMENT_NODE) {
- String key = filterNode.getNodeName();
- String value = filterNode.getTextContent();
- params.put(key, value);
- }
- }
- return params;
- }
-
}
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentFactory.java
index a0d81e8..59d4b69 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentFactory.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentFactory.java
@@ -16,18 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.tamaya.metamodel.internal;
import org.apache.tamaya.spi.ServiceContextManager;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
@@ -86,23 +80,23 @@ public final class ComponentFactory<T> {
return comp;
}
- public Collection<T> loadInstances(NodeList nodeList) {
- List<T> items = new ArrayList<>();
- for(int i=0;i<nodeList.getLength();i++){
- Node node = nodeList.item(i);
- if(node.getNodeName().equals("filter")){
- String type = node.getNodeValue();
- try {
- T item = getComponent(type);
- ComponentConfigurator.configure(item, node);
- items.add(item);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- return items;
- }
+// public Collection<T> loadInstances(NodeList nodeList) {
+// List<T> items = new ArrayList<>();
+// for(int i=0;i<nodeList.getLength();i++){
+// Node node = nodeList.item(i);
+// if(node.getNodeName().equals("filter")){
+// String type = node.getNodeValue();
+// try {
+// T item = getComponent(type);
+// ComponentConfigurator.configure(item, node);
+// items.addPropertyValue(item);
+// } catch (Exception e) {
+// e.printStackTrace();
+// }
+// }
+// }
+// return items;
+// }
@Override
public String toString() {
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/MetaContextReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/MetaContextReader.java
deleted file mode 100644
index d2d1801..0000000
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/MetaContextReader.java
+++ /dev/null
@@ -1,189 +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.metamodel.internal;
-
-import org.apache.tamaya.metamodel.MetaContext;
-import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
-import org.apache.tamaya.metamodel.spi.SimpleResolver;
-import org.apache.tamaya.spi.ConfigurationBuilder;
-import org.apache.tamaya.spi.ServiceContextManager;
-import org.osgi.service.component.annotations.Component;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import javax.annotation.Priority;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Logger;
-
-
-/**
- * Meta-configuration reader that reads the shared context data.
- */
-@Priority(-1)
-@Component
-public class MetaContextReader implements MetaConfigurationReader {
-
- private static final Logger LOG = Logger.getLogger(MetaContextReader.class.getName());
- private static final int INVALUE = 0;
- private static final int BEFORE_EXP = 1;
- private static final int INEXP = 2;
-
- private Map<String,SimpleResolver> resolvers = new ConcurrentHashMap<>();
-
- public MetaContextReader(){
- for(SimpleResolver resolver: ServiceContextManager.getServiceContext()
- .getServices(SimpleResolver.class)){
- this.resolvers.put(resolver.getResolverId(), resolver);
- }
- }
-
- public void addResolver(SimpleResolver resolver){
- if(!this.resolvers.containsKey(resolver.getResolverId())) {
- this.resolvers.put(resolver.getResolverId(), resolver);
- }
- }
-
- public void removeResolver(SimpleResolver resolver){
- this.resolvers.remove(resolver.getResolverId());
- }
-
- public Set<String> getResolverIds(){
- return this.resolvers.keySet();
- }
-
- public SimpleResolver getResolver(String resolverKey){
- return this.resolvers.get(resolverKey);
- }
-
- @Override
- public void read(Document document, ConfigurationBuilder configBuilder) {
- NodeList nodeList = document.getDocumentElement().getElementsByTagName("context");
- LOG.finer("Reading " + nodeList.getLength() + " getMeta context entries...");
- for(int i=0;i<nodeList.getLength();i++){
- Node node = nodeList.item(i);
- if(node.getNodeName().equals("context")){
- MetaContext context = MetaContext.getInstance();
- NodeList entryNodes = node.getChildNodes();
- for(int c=0;c<entryNodes.getLength();c++){
- Node entryNode = entryNodes.item(c);
- if(entryNode.getNodeType()==Node.ELEMENT_NODE) {
- String key = entryNode.getNodeName();
- String value = entryNode.getTextContent();
- value = resolvePlaceholders(value);
- LOG.finest("MetaContext: " + key + '=' + value);
- context.setProperty(key, value);
- }
- }
- }
- }
- }
-
- private String resolvePlaceholders(String value) {
- StringBuilder result = new StringBuilder();
- StringBuilder exp = new StringBuilder();
- int state = INVALUE;
- StringTokenizer tokenizer = new StringTokenizer(value, "${}", true);
- while(tokenizer.hasMoreTokens()){
- String token = tokenizer.nextToken();
- switch(token){
- case "$":
- switch(state){
- case BEFORE_EXP: // escaped
- result.append(token);
- state = INVALUE;
- break;
- case INEXP:
- exp.append(token);
- break;
- case INVALUE:
- default:
- state = BEFORE_EXP;
- break;
- }
- break;
- case "{":
- switch(state){
- case BEFORE_EXP:
- state = INEXP;
- break;
- case INVALUE:
- case INEXP:
- default:
- result.append(token);
- break;
- }
- break;
- case "}":
- switch(state){
- case INVALUE:
- result.append(token);
- break;
- case INEXP:
- result.append(evaluateExpression(exp.toString()));
- exp.setLength(0);
- state = INVALUE;
- break;
- case BEFORE_EXP:
- result.append("$").append(token);
- state = INVALUE;
- break;
- default:
- break;
- }
- break;
- default:
- switch(state){
- case INEXP:
- exp.append(token);
- break;
- default:
- result.append(token);
- break;
- }
-
- }
- }
- return result.toString();
- }
-
- private String evaluateExpression(String exp) {
- String[] parts = exp.split(":", 2);
- if(parts.length<2){
- return "--{MISSING RESOLVER ID in "+exp+"}";
- }
- SimpleResolver resolver = this.resolvers.get(parts[0]);
- if(resolver==null){
- return "--{NO RESOLVER FOUND for "+exp+"}";
- }
- try{
- String resolved = resolver.evaluate(parts[1]);
- if(resolved==null) {
- return "--{NOT RESOLVABLE:" + exp + "}";
- }else{
- return resolved;
- }
- }catch(Exception e){
- return "--{ERROR:"+exp+":"+e+"}";
- }
- }
-}
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyConverterReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyConverterReader.java
index 751970e..3f628de 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyConverterReader.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyConverterReader.java
@@ -18,17 +18,17 @@
*/
package org.apache.tamaya.metamodel.internal;
-import org.apache.tamaya.ConfigException;
import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.format.ConfigurationData;
import org.apache.tamaya.metamodel.spi.ItemFactory;
import org.apache.tamaya.metamodel.spi.ItemFactoryManager;
import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
import org.apache.tamaya.spi.ConfigurationBuilder;
+import org.apache.tamaya.spi.ListValue;
+import org.apache.tamaya.spi.ObjectValue;
import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.PropertyValue;
import org.osgi.service.component.annotations.Component;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
import java.util.Map;
import java.util.logging.Level;
@@ -43,22 +43,27 @@ public class PropertyConverterReader implements MetaConfigurationReader{
private static final Logger LOG = Logger.getLogger(PropertyConverterReader.class.getName());
@Override
- public void read(Document document, ConfigurationBuilder configBuilder) {
- NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-converters");
- if(nodeList.getLength()==0){
- LOG.finer("No property converters configured");
+ public void read(ConfigurationData metaConfig, ConfigurationBuilder configBuilder) {
+ ObjectValue root = ObjectValue.from(metaConfig.getData());
+ if(root.getPropertyValue("converters")==null){
+ LOG.finer("No property converters configured.");
return;
}
- if(nodeList.getLength()>1){
- throw new ConfigException("Only one single property-converters section allowed.");
- }
- nodeList = nodeList.item(0).getChildNodes();
- for(int i=0;i<nodeList.getLength();i++){
- Node node = nodeList.item(i);
- if(node.getNodeType()!=Node.ELEMENT_NODE) {
+ ListValue nodeList = root.getPropertyValue("converters").toListValue();
+ ListValue listValue = nodeList.toListValue();
+ for(PropertyValue converterNode:listValue){
+
+ if(converterNode.getValueType()!= PropertyValue.ValueType.MAP) {
+ continue;
+ }
+ ObjectValue ov = converterNode.toObjectValue();
+ if(ov.getPropertyValue("properties")==null){
+ LOG.severe("No property converter configured.");
continue;
}
- String type = node.getNodeName();
+ ObjectValue propertyValue = ov.getPropertyValue("properties").toObjectValue();
+ Map<String,String> properties = propertyValue!=null? propertyValue.toLocalMap(): null;
+ String type = ItemFactoryManager.getType(ov);
if("defaults".equals(type)){
LOG.finer("Adding default property converters...");
configBuilder.addDefaultPropertyConverters();
@@ -70,11 +75,10 @@ public class PropertyConverterReader implements MetaConfigurationReader{
LOG.severe("No such property converter: " + type);
continue;
}
- Map<String,String> params = ComponentConfigurator.extractParameters(node);
- PropertyConverter converter = converterFactory.create(params);
+ PropertyConverter converter = converterFactory.create(ov.toMap());
if(converter!=null) {
- ComponentConfigurator.configure(converter, node);
- Class targetType = Class.forName(params.get("targetType"));
+ ComponentConfigurator.configure(converter, properties);
+ Class targetType = Class.forName(ov.getValue("targetType"));
LOG.finer("Adding converter for type " + targetType.getName() + ": " + converter.getClass());
configBuilder.addPropertyConverters(TypeLiteral.of(targetType), converter);
}
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterOrderingReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterOrderingReader.java
index 48ddcf0..523f1a0 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterOrderingReader.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterOrderingReader.java
@@ -18,18 +18,18 @@
*/
package org.apache.tamaya.metamodel.internal;
-import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.format.ConfigurationData;
import org.apache.tamaya.metamodel.spi.ItemFactory;
import org.apache.tamaya.metamodel.spi.ItemFactoryManager;
import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
import org.apache.tamaya.spi.ConfigurationBuilder;
+import org.apache.tamaya.spi.ObjectValue;
+import org.apache.tamaya.spi.PropertyValue;
import org.osgi.service.component.annotations.Component;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
import javax.annotation.Priority;
import java.util.Comparator;
+import java.util.Map;
import java.util.logging.Logger;
@@ -43,23 +43,27 @@ public class PropertyFilterOrderingReader implements MetaConfigurationReader{
private static final Logger LOG = Logger.getLogger(PropertyFilterOrderingReader.class.getName());
@Override
- public void read(Document document, ConfigurationBuilder configBuilder) {
- NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-filter-order");
- if(nodeList.getLength()==0){
- LOG.finer("No property filter ordering configured.");
+ public void read(ConfigurationData metaConfig, ConfigurationBuilder configBuilder) {
+ ObjectValue root = ObjectValue.from(metaConfig.getData());
+ if(root.getPropertyValue("filter-order")==null){
+ LOG.finer("No property filter ordering defined.");
return;
}
- if(nodeList.getLength()>1){
- throw new ConfigException("Only one property filter order can be applied.");
+ ObjectValue value = root.getPropertyValue("filter-order").toObjectValue();
+ if(value.getValueType()== PropertyValue.ValueType.MAP){
+ ObjectValue ov = value.toObjectValue();
+ PropertyValue type = ov.getPropertyValue("type");
+ if(type==null){
+ type = ov.getPropertyValue("class");
+ ItemFactory<Comparator> comparatorFactory = ItemFactoryManager.getInstance()
+ .getFactory(Comparator.class, type.getValue());
+ Map<String,String> properties = ov.toLocalMap();
+ Comparator comparator = comparatorFactory.create(properties);
+ ComponentConfigurator.configure(comparator, properties);
+ LOG.finer("Sorting property filters using comparator: " + comparator.getClass().getName());
+ configBuilder.sortPropertyFilter(comparator);
+ }
}
- Node node = nodeList.item(0);
- String type = node.getAttributes().getNamedItem("type").getNodeValue();
- ItemFactory<Comparator> comparatorFactory = ItemFactoryManager.getInstance().getFactory(Comparator.class, type);
- Comparator comparator = comparatorFactory.create(ComponentConfigurator.extractParameters(node));
- ComponentConfigurator.configure(comparator, node);
- LOG.finer("Sorting property filters using comparator: " + comparator.getClass().getName());
- configBuilder.sortPropertyFilter(comparator);
}
-
}
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterReader.java
index 415bac5..7f857d5 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterReader.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterReader.java
@@ -18,18 +18,19 @@
*/
package org.apache.tamaya.metamodel.internal;
-import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.format.ConfigurationData;
import org.apache.tamaya.metamodel.spi.ItemFactory;
import org.apache.tamaya.metamodel.spi.ItemFactoryManager;
import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
import org.apache.tamaya.spi.ConfigurationBuilder;
+import org.apache.tamaya.spi.ListValue;
+import org.apache.tamaya.spi.ObjectValue;
import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
import org.osgi.service.component.annotations.Component;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
import java.util.Map;
+import java.util.logging.Level;
import java.util.logging.Logger;
@@ -42,38 +43,42 @@ public class PropertyFilterReader implements MetaConfigurationReader{
private static final Logger LOG = Logger.getLogger(PropertyFilterReader.class.getName());
@Override
- public void read(Document document, ConfigurationBuilder configBuilder) {
- NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-filters");
- if(nodeList.getLength()==0){
- LOG.finer("No property filters configured.");
+ public void read(ConfigurationData metaConfig, ConfigurationBuilder configBuilder) {
+ ObjectValue root = ObjectValue.from(metaConfig.getData());
+ if (root.getPropertyValue("filters") == null) {
+ LOG.finer("No property filters configured");
return;
}
- if(nodeList.getLength()>1){
- throw new ConfigException("Only one single property-filters section allowed.");
- }
- nodeList = nodeList.item(0).getChildNodes();
- for(int i=0;i<nodeList.getLength();i++){
- Node node = nodeList.item(i);
- if(node.getNodeType()!=Node.ELEMENT_NODE) {
+ ListValue nodeList = root.getPropertyValue("filters").toListValue();
+ ListValue listValue = nodeList.toListValue();
+ for (PropertyValue filterNode : listValue) {
+
+ if (filterNode.getValueType() != PropertyValue.ValueType.MAP) {
continue;
}
- String type = node.getNodeName();
+ ObjectValue ov = filterNode.toObjectValue();
+ String type = ItemFactoryManager.getType(ov);
if ("defaults".equals(type)) {
LOG.finer("Adding default property filters...");
configBuilder.addDefaultPropertyFilters();
continue;
}
- ItemFactory<PropertyFilter> filterFactory = ItemFactoryManager.getInstance().getFactory(PropertyFilter.class, type);
- if(filterFactory==null){
- LOG.severe("No such property filter: " + type);
- continue;
- }
- Map<String,String> params = ComponentConfigurator.extractParameters(node);
- PropertyFilter filter = filterFactory.create(params);
- if(filter!=null) {
- ComponentConfigurator.configure(filter, params);
- LOG.finer("Adding configured property filter: " + filter.getClass().getName());
- configBuilder.addPropertyFilters(filter);
+ ObjectValue propertyValue = ov.getPropertyValue("properties").toObjectValue();
+ Map<String,String> properties = propertyValue!=null? propertyValue.toLocalMap(): null;
+ try {
+ ItemFactory<PropertyFilter> filterFactory = ItemFactoryManager.getInstance().getFactory(PropertyFilter.class, type);
+ if (filterFactory == null) {
+ LOG.severe("No such property filter: " + type);
+ continue;
+ }
+ PropertyFilter filter = filterFactory.create(properties);
+ if (filter != null) {
+ ComponentConfigurator.configure(filter, properties);
+ LOG.finer("Adding filter: " + filter.getClass());
+ configBuilder.addPropertyFilters(filter);
+ }
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Failed to configure PropertyFilter: " + type, e);
}
}
}
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceOrderingReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceOrderingReader.java
index c03e4de..ad33a52 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceOrderingReader.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceOrderingReader.java
@@ -18,18 +18,18 @@
*/
package org.apache.tamaya.metamodel.internal;
-import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.format.ConfigurationData;
import org.apache.tamaya.metamodel.spi.ItemFactory;
import org.apache.tamaya.metamodel.spi.ItemFactoryManager;
import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
import org.apache.tamaya.spi.ConfigurationBuilder;
+import org.apache.tamaya.spi.ObjectValue;
+import org.apache.tamaya.spi.PropertyValue;
import org.osgi.service.component.annotations.Component;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
import javax.annotation.Priority;
import java.util.Comparator;
+import java.util.Map;
import java.util.logging.Logger;
@@ -43,23 +43,26 @@ public class PropertySourceOrderingReader implements MetaConfigurationReader{
private static final Logger LOG = Logger.getLogger(PropertySourceOrderingReader.class.getName());
@Override
- public void read(Document document, ConfigurationBuilder configBuilder) {
- NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-source-order");
- if(nodeList.getLength()==0){
+ public void read(ConfigurationData metaConfig, ConfigurationBuilder configBuilder) {
+ ObjectValue root = ObjectValue.from(metaConfig.getData());
+
+ if(root.getPropertyValue("source-order")==null){
LOG.finer("No property source ordering defined.");
return;
}
- if(nodeList.getLength()>1){
- throw new ConfigException("Only one property source order can be applied.");
+ ObjectValue value = root.getPropertyValue("source-order").toObjectValue();
+ if(value.getValueType()== PropertyValue.ValueType.MAP){
+ ObjectValue ov = value.toObjectValue();
+ String type = ItemFactoryManager.getType(ov);
+ if(type!=null){
+ ItemFactory<Comparator> comparatorFactory = ItemFactoryManager.getInstance()
+ .getFactory(Comparator.class, type);
+ Map<String,String> properties = ov.toLocalMap();
+ Comparator comparator = comparatorFactory.create(properties);
+ ComponentConfigurator.configure(comparator, properties);
+ LOG.finer("Sorting property sources using comparator: " + comparator.getClass().getName());
+ configBuilder.sortPropertySources(comparator);
+ }
}
- Node node = nodeList.item(0);
- String type = node.getAttributes().getNamedItem("type").getNodeValue();
- ItemFactory<Comparator> comparatorFactory = ItemFactoryManager.getInstance().getFactory(Comparator.class, type);
- Comparator comparator = comparatorFactory.create(ComponentConfigurator.extractParameters(node));
- ComponentConfigurator.configure(comparator, node);
- LOG.finer("Sorting property sources using comparator: " + comparator.getClass().getName());
- configBuilder.sortPropertySources(comparator);
}
-
-
}
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
index bb06aa0..5c312ed 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
@@ -18,9 +18,8 @@
*/
package org.apache.tamaya.metamodel.internal;
-import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.format.ConfigurationData;
import org.apache.tamaya.metamodel.EnabledPropertySource;
-import org.apache.tamaya.metamodel.MetaContext;
import org.apache.tamaya.metamodel.ext.EnabledPropertySourceProvider;
import org.apache.tamaya.metamodel.ext.FilteredPropertySource;
import org.apache.tamaya.metamodel.ext.RefreshablePropertySource;
@@ -29,13 +28,13 @@ import org.apache.tamaya.metamodel.spi.ItemFactory;
import org.apache.tamaya.metamodel.spi.ItemFactoryManager;
import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
import org.apache.tamaya.spi.ConfigurationBuilder;
+import org.apache.tamaya.spi.ListValue;
+import org.apache.tamaya.spi.ObjectValue;
import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.PropertyValue;
import org.osgi.service.component.annotations.Component;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
import java.util.Map;
import java.util.logging.Level;
@@ -50,61 +49,64 @@ public class PropertySourceReader implements MetaConfigurationReader{
private static final Logger LOG = Logger.getLogger(PropertySourceReader.class.getName());
@Override
- public void read(Document document, ConfigurationBuilder configBuilder) {
- NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-sources");
- if(nodeList.getLength()==0){
- LOG.finer("No property sources configured.");
+ public void read(ConfigurationData metaConfig, ConfigurationBuilder configBuilder) {
+ ObjectValue root = ObjectValue.from(metaConfig.getData());
+ PropertyValue nodeList = root.getPropertyValue("sources");
+ if (nodeList == null) {
+ LOG.finer("No property sources configured");
return;
}
- if(nodeList.getLength()>1){
- throw new ConfigException("Only one single property-source section allowed.");
- }
- nodeList = nodeList.item(0).getChildNodes();
- for(int i=0;i<nodeList.getLength();i++){
- Node node = nodeList.item(i);
- if(node.getNodeType()!=Node.ELEMENT_NODE) {
+ ListValue listValue = nodeList.toListValue();
+ for (PropertyValue node : listValue) {
+ if(node.getValueType()!= PropertyValue.ValueType.MAP) {
continue;
}
- String type = node.getNodeName();
- if("defaults".equals(type)){
- LOG.fine("Adding default property sources.");
+ ObjectValue ov = node.toObjectValue();
+ ObjectValue propertyValue = ov.getPropertyValue("properties").toObjectValue();
+ Map<String,String> params = propertyValue!=null? propertyValue.toLocalMap(): null;
+ String type = ItemFactoryManager.getType(ov);
+ if ("defaults".equals(type)) {
+ LOG.finer("Adding default property sources...");
configBuilder.addDefaultPropertySources();
continue;
}
- try {
- ItemFactory<PropertySource> sourceFactory = ItemFactoryManager.getInstance().getFactory(PropertySource.class, type);
- if (sourceFactory != null) {
- LOG.fine("Property source found: " + type);
- Map<String, String> params = ComponentConfigurator.extractParameters(node);
+ boolean isProvider = ov.getValue("provider")!=null?Boolean.valueOf(ov.getValue("provider")):false;
+ if(isProvider) {
+ try {
+ ItemFactory<PropertySourceProvider> providerFactory = ItemFactoryManager.getInstance().getFactory(PropertySourceProvider.class, type);
+ if(providerFactory==null){
+ LOG.fine("No such property source provider: " + type);
+ continue;
+ }
+ PropertySourceProvider prov = providerFactory.create(params);
+ if(prov!=null) {
+ ComponentConfigurator.configure(prov, params);
+ prov = decoratePropertySourceProvider(prov, ov.toLocalMap());
+ LOG.finer("Adding configured property source provider: " + prov.getClass().getName());
+ configBuilder.addPropertySources(prov.getPropertySources());
+ }
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Failed to configure PropertySourceProvider: " + type, e);
+ }
+ }else{
+ try {
+ ItemFactory<PropertySource> sourceFactory = ItemFactoryManager.getInstance().getFactory(PropertySource.class, type);
+ if (sourceFactory == null) {
+ LOG.severe("No such property source: " + type);
+ continue;
+ }
PropertySource ps = sourceFactory.create(params);
if (ps != null) {
ComponentConfigurator.configure(ps, params);
- ps = decoratePropertySource(ps, node, params);
+ ps = decoratePropertySource(ps, ov);
LOG.finer("Adding configured property source: " + ps.getName());
configBuilder.addPropertySources(ps);
continue;
}
- }
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Failed to configure PropertySource: " + type, e);
- continue;
- }
- try {
- ItemFactory<PropertySourceProvider> providerFactory = ItemFactoryManager.getInstance().getFactory(PropertySourceProvider.class, type);
- if(providerFactory==null){
- LOG.fine("No such property source provider: " + type);
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Failed to configure PropertySource: " + type, e);
continue;
}
- Map<String,String> params = ComponentConfigurator.extractParameters(node);
- PropertySourceProvider prov = providerFactory.create(params);
- if(prov!=null) {
- ComponentConfigurator.configure(prov, node);
- prov = decoratePropertySourceProvider(prov, node, params);
- LOG.finer("Adding configured property source provider: " + prov.getClass().getName());
- configBuilder.addPropertySources(prov.getPropertySources());
- }
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Failed to configure PropertySourceProvider: " + type, e);
}
}
}
@@ -112,47 +114,47 @@ public class PropertySourceReader implements MetaConfigurationReader{
/**
* Decorates a property source to be refreshable or filtered.
* @param ps the wrapped property source
- *@param configNode the XML config value
- * @param params the extracted parameter createList @return the property source to be added to the context.
+ * @param configNode the config value
+ * @return the property source to be added to the context.
*/
- private PropertySource decoratePropertySource(PropertySource ps, Node configNode, Map<String, String> params){
- Node refreshableVal = configNode.getAttributes().getNamedItem("refreshable");
- if(refreshableVal!=null && Boolean.parseBoolean(refreshableVal.getNodeValue())){
- ps = RefreshablePropertySource.of(params, ps);
+ private PropertySource decoratePropertySource(PropertySource ps, ObjectValue configNode){
+ Map<String,String> params = configNode.toMap();
+ boolean refreshable = Boolean.parseBoolean(params.get("refreshable"));
+ if(refreshable){
+ ps = RefreshablePropertySource.of(ps);
}
- Node enabledVal = configNode.getAttributes().getNamedItem("enabled");
+ String enabledVal = params.get("enabled");
if(enabledVal!=null){
- ps = new EnabledPropertySource(ps,
- MetaContext.getInstance().getProperties(),
- enabledVal.getNodeValue());
+ ps = new EnabledPropertySource(ps, enabledVal);
}
- NodeList childNodes = configNode.getChildNodes();
- for(int i=0;i<childNodes.getLength();i++){
- Node node = childNodes.item(i);
- if("filters".equals(node.getNodeName())){
- ps = FilteredPropertySource.of(ps);
- NodeList filterNodes = node.getChildNodes();
- for(int f=0;f<filterNodes.getLength();f++) {
- Node filterNode = filterNodes.item(f);
- configureFilter((FilteredPropertySource) ps, filterNode);
- }
+ PropertyValue childNodes = configNode.getPropertyValue("filters");
+ if(childNodes!=null) {
+ ListValue listValue = childNodes.toListValue();
+ ps = FilteredPropertySource.of(ps);
+ for (PropertyValue filterNode:listValue) {
+ ObjectValue ov = filterNode.toObjectValue();
+ configureFilter((FilteredPropertySource) ps, ov);
}
}
return ps;
}
- private void configureFilter(FilteredPropertySource ps, Node filterNode) {
+ private void configureFilter(FilteredPropertySource ps, ObjectValue filterNode) {
try {
- String type = filterNode.getNodeName();
- ItemFactory<PropertyFilter> filterFactory = ItemFactoryManager.getInstance().getFactory(PropertyFilter.class, type);
+ String type = ItemFactoryManager.getType(filterNode);
+ if(type==null){
+ return;
+ }
+ ItemFactory<PropertyFilter> filterFactory = ItemFactoryManager.getInstance()
+ .getFactory(PropertyFilter.class, type);
if(filterFactory==null){
LOG.severe("No such property filter: " + type);
return;
}
- Map<String,String> params = ComponentConfigurator.extractParameters(filterNode);
- PropertyFilter filter = filterFactory.create(params);
+ Map<String,String> properties = filterNode.toMap();
+ PropertyFilter filter = filterFactory.create(properties);
if(filter!=null) {
- ComponentConfigurator.configure(filter, params);
+ ComponentConfigurator.configure(filter, properties);
LOG.finer("Adding configured property filter: " + filter.getClass().getName());
ps.addPropertyFilter(filter);
}
@@ -164,21 +166,19 @@ public class PropertySourceReader implements MetaConfigurationReader{
/**
* Decorates a property source provider to be refreshable or filtered.
* @param prov the property source provider to be wrapped.
- * @param configNode the XML config value
- * @param params the extracted parameter createList @return the property source provider to be added to the context.
+ * @param properties the config properties
*/
- private PropertySourceProvider decoratePropertySourceProvider(PropertySourceProvider prov, Node configNode, Map<String, String> params){
- Node refreshableVal = configNode.getAttributes().getNamedItem("refreshable");
+ private PropertySourceProvider decoratePropertySourceProvider(PropertySourceProvider prov, Map<String, String> properties){
+ boolean refreshable = Boolean.parseBoolean(properties.get("refreshable"));
// Refreshable
- if(refreshableVal!=null && Boolean.parseBoolean(refreshableVal.getNodeValue())){
- prov = RefreshablePropertySourceProvider.of(params, prov);
+ if(refreshable){
+ prov = RefreshablePropertySourceProvider.of(prov);
}
// Enabled
- Node enabledVal = configNode.getAttributes().getNamedItem("enabled");
- if(enabledVal!=null){
+ String enabled = properties.get("enabled");
+ if(enabled!=null){
prov = new EnabledPropertySourceProvider(prov,
- MetaContext.getInstance().getProperties(),
- enabledVal.getNodeValue());
+ enabled);
}
return prov;
}
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java
index 04dfc4c..c4e6d02 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java
@@ -32,7 +32,7 @@ import java.util.Map;
public final class CLIArgumentsFactory implements ItemFactory<PropertySource>{
@Override
public String getName() {
- return "CLI";
+ return "cli";
}
@Override
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ClasspathPropertySourceFactory.java
similarity index 76%
copy from metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactory.java
copy to metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ClasspathPropertySourceFactory.java
index 76472a5..ff1d7a9 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactory.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ClasspathPropertySourceFactory.java
@@ -28,19 +28,23 @@ import java.util.logging.Logger;
* Factory for configuring resource based property sources.
*/
@Component
-public class ResourcePropertySourceFactory extends URLPropertySourceFactory{
+public class ClasspathPropertySourceFactory extends URLPropertySourceFactory{
- private static final Logger LOG = Logger.getLogger(ResourcePropertySourceFactory.class.getName());
+ private static final Logger LOG = Logger.getLogger(ClasspathPropertySourceFactory.class.getName());
@Override
public String getName() {
- return "resource";
+ return "classpath";
}
protected String example() {
- return "<resource location=\"META-INF/config.xml\"\n" +
- " formats=\"xml-properties\")>\n";
+ return "{ type: classpath\n" +
+ " properties: {\n" +
+ " location=\"META-INF/config.xml\"\n" +
+ " format=\"xml-properties\"\n" +
+ " }\n" +
+ "}\n";
}
protected URL createResource(String location) {
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/EnvironmentVariablesFactory.java
similarity index 80%
copy from metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java
copy to metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/EnvironmentVariablesFactory.java
index 04dfc4c..1653754 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/EnvironmentVariablesFactory.java
@@ -16,28 +16,29 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.tamaya.metamodel.internal.factories;
import org.apache.tamaya.metamodel.spi.ItemFactory;
import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spisupport.propertysource.CLIPropertySource;
+import org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource;
import org.osgi.service.component.annotations.Component;
import java.util.Map;
/**
- * Factory for configuring CLI argument based property sources.
+ * Factory for configuring environment properties based property sources.
*/
@Component
-public final class CLIArgumentsFactory implements ItemFactory<PropertySource>{
+public final class EnvironmentVariablesFactory implements ItemFactory<PropertySource>{
@Override
public String getName() {
- return "CLI";
+ return "environment-variables";
}
@Override
public PropertySource create(Map<String,String> parameters) {
- return new CLIPropertySource();
+ return new EnvironmentPropertySource();
}
@Override
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactory.java
index c2ebe15..6b2f14c 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactory.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactory.java
@@ -42,8 +42,12 @@ public final class FilePropertySourceFactory extends ResourcePropertySourceFacto
@Override
protected String example() {
- return "<file location=\"c:/temp/config.xml\"\n" +
- " formats=\"xml-properties\")>\n";
+ return "{ type: file\n" +
+ " properties: {\n" +
+ " location=\"c:/temp/config.xml\"\n" +
+ " format=\"xml-properties\"\n" +
+ " }\n" +
+ "}\n";
}
@Override
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactory.java
index 76472a5..f9d58cb 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactory.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactory.java
@@ -39,8 +39,12 @@ public class ResourcePropertySourceFactory extends URLPropertySourceFactory{
protected String example() {
- return "<resource location=\"META-INF/config.xml\"\n" +
- " formats=\"xml-properties\")>\n";
+ return "{ type: resource\n" +
+ " properties: {\n" +
+ " location=\"META-INF/config.xml\"\n" +
+ " format=\"xml-properties\"\n" +
+ " }\n" +
+ "}\n";
}
protected URL createResource(String location) {
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactory.java
index 8072a15..3861a9a 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactory.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactory.java
@@ -99,8 +99,13 @@ public class ResourcePropertySourceProviderFactory implements ItemFactory<Proper
}
protected String example() {
- return "<resources location\"/META-INF/**/config.xml\"\n" +
- " formats=\"xml-properties\"\n/>";
+ return "{ type: resources\n" +
+ " provider: true\n" +
+ " properties: {\n" +
+ " location=\"META-INF/**/config.xml\"\n" +
+ " format=\"xml-properties\"\n" +
+ " }\n" +
+ "}\n";
}
protected Collection<URL> createResources(String location) {
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/SystemPropertiesFactory.java
similarity index 81%
copy from metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java
copy to metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/SystemPropertiesFactory.java
index 04dfc4c..05b2cb2 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/SystemPropertiesFactory.java
@@ -16,28 +16,29 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.tamaya.metamodel.internal.factories;
import org.apache.tamaya.metamodel.spi.ItemFactory;
import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spisupport.propertysource.CLIPropertySource;
+import org.apache.tamaya.spisupport.propertysource.SystemPropertySource;
import org.osgi.service.component.annotations.Component;
import java.util.Map;
/**
- * Factory for configuring CLI argument based property sources.
+ * Factory for configuring system properties based property sources.
*/
@Component
-public final class CLIArgumentsFactory implements ItemFactory<PropertySource>{
+public final class SystemPropertiesFactory implements ItemFactory<PropertySource>{
@Override
public String getName() {
- return "CLI";
+ return "system-properties";
}
@Override
public PropertySource create(Map<String,String> parameters) {
- return new CLIPropertySource();
+ return new SystemPropertySource();
}
@Override
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactory.java
index b5689d1..3682f08 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactory.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactory.java
@@ -69,8 +69,12 @@ public class URLPropertySourceFactory implements ItemFactory<PropertySource>{
}
protected String example() {
- return "<url location=\"http://127.0.0.1:1110/config.xml\"\n" +
- " formats=\"xml-properties\"\n/>";
+ return "{ type: url\n" +
+ " properties: {\n" +
+ " location=\"http://127.0.0.1:1110/config.xml\"\n" +
+ " format=\"xml-properties\"\n" +
+ " }\n" +
+ "}\n";
}
protected URL createResource(String location) {
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolver.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolver.java
index 19284fd..704992a 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolver.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolver.java
@@ -24,12 +24,10 @@ import bsh.Interpreter;
import bsh.NameSpace;
import bsh.UtilEvalError;
import org.apache.tamaya.metamodel.MetaContext;
-import org.apache.tamaya.metamodel.spi.SimpleResolver;
import org.osgi.service.component.annotations.Component;
import java.io.*;
import java.util.Map;
-import java.util.logging.Level;
import java.util.logging.Logger;
/**
@@ -43,38 +41,24 @@ import java.util.logging.Logger;
* </ul>
*/
@Component
-public final class JavaResolver implements SimpleResolver{
+public final class JavaResolver {
private static final Logger LOG = Logger.getLogger(JavaResolver.class.getName());
-
- @Override
public String getResolverId() {
return "java";
}
- @Override
- public String evaluate(String expression) {
- try{
- return String.valueOf(evaluate(expression, null));
- }catch(Exception e){
- LOG.log(Level.WARNING, "Error evaluating expression: " + expression, e);
- return "ERROR{"+expression+"}:"+e;
- }
- }
-
- public Object evaluate(String expression, Map<String, String> context) throws UtilEvalError, EvalError {
+ public Object evaluate(String expression) throws UtilEvalError, EvalError {
BshClassManager bshClassManager = new BshClassManager();
NameSpace namespace = new NameSpace(bshClassManager, "config");
namespace.loadDefaultImports();
namespace.importStatic(JavaResolver.class);
- namespace.setVariable("contextprops", MetaContext.getInstance(), false);
+ namespace.setVariable("context", MetaContext.getInstance(), false);
namespace.setVariable("envprops", System.getenv(), false);
namespace.setVariable("sysprops", System.getProperties(), false);
- if(context!=null){
- for(Map.Entry<String,String> en:context.entrySet()){
- namespace.setVariable(en.getKey(), en.getValue(), false);
- }
+ for(Map.Entry<String,Object> en:MetaContext.getInstance().getProperties().entrySet()){
+ namespace.setVariable(en.getKey(), en.getValue(), false);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream outStream = new PrintStream(out);
@@ -89,7 +73,8 @@ public final class JavaResolver implements SimpleResolver{
}
public static String context(String key){
- return MetaContext.getInstance().getProperty(key);
+ return MetaContext.getInstance().getStringProperty(key)
+ .orElse(null);
}
public static String env(String key){
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolver.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolver.java
index a3dfcb3..38cbece 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolver.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolver.java
@@ -19,7 +19,6 @@
package org.apache.tamaya.metamodel.internal.resolver;
import org.apache.tamaya.metamodel.MetaContext;
-import org.apache.tamaya.metamodel.spi.SimpleResolver;
import org.osgi.service.component.annotations.Component;
/**
@@ -36,13 +35,12 @@ import org.osgi.service.component.annotations.Component;
* Hereby the _default_ parameter defines the default createValue to be applied, if no createValue was found.
*/
@Component
-public final class PropertiesResolver implements SimpleResolver{
- @Override
+public final class PropertiesResolver {
+
public String getResolverId() {
return "properties";
}
- @Override
public String evaluate(String expression) {
String[] mainParts = expression.split("\\?",2);
if(mainParts.length==1){
@@ -68,8 +66,7 @@ public final class PropertiesResolver implements SimpleResolver{
}
return val;
case "ctx":
- return MetaContext.getInstance()
- .getProperty(parts[1], defaultValue);
+ return MetaContext.getInstance().getStringProperty(parts[1]).orElse(defaultValue);
default:
return null;
}
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/SimpleResolver.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/ContextInitializer.java
similarity index 84%
rename from metamodel/src/main/java/org/apache/tamaya/metamodel/spi/SimpleResolver.java
rename to metamodel/src/main/java/org/apache/tamaya/metamodel/spi/ContextInitializer.java
index eaf0749..aedf7df 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/SimpleResolver.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/ContextInitializer.java
@@ -18,24 +18,19 @@
*/
package org.apache.tamaya.metamodel.spi;
+import org.apache.tamaya.metamodel.MetaContext;
+
/**
* SPI interface for implementations of simple expression types for use within
* {@link org.apache.tamaya.metamodel.MetaContext} getMeta-configuration entries.
*/
-public interface SimpleResolver {
+public interface ContextInitializer {
/**
* Get the expression id, which is the first part of a placeholder expression
* ({@code ${expressionId:expression}}).
* @return the expression id, never null.
*/
- String getResolverId();
-
- /**
- * Evaluate an expression.
- * @param expression the expression.
- * @return the result, or null.
- */
- String evaluate(String expression);
+ void initializeContext(MetaContext metaContext);
}
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/ItemFactoryManager.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/ItemFactoryManager.java
index 4ca403d..f72a847 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/ItemFactoryManager.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/ItemFactoryManager.java
@@ -28,6 +28,8 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.tamaya.spi.ObjectValue;
+import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spi.ServiceContextManager;
/**
@@ -49,6 +51,26 @@ public final class ItemFactoryManager {
return INSTANCE;
}
+ /**
+ * Extracts the target type by evaluating any {@code type, class} attributes.
+ * @param objectValue the config value.
+ * @return the type/class name, or null.
+ */
+ public static String getType(ObjectValue objectValue) {
+ if(objectValue==null){
+ return null;
+ }
+ PropertyValue val = objectValue.getPropertyValue("type");
+ if(val == null){
+ val = objectValue.getPropertyValue("class");
+ }
+ if(val==null){
+ LOG.severe("Type definition requires either type or class declaration: " + objectValue);
+ return null;
+ }
+ return val.getValue();
+ }
+
public <T> List<ItemFactory<T>> getFactories(Class<T> type){
List<ItemFactory<?>> factories = factoryRegistry.get(type);
if(factories==null){
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/MetaConfigurationReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/MetaConfigurationReader.java
index e00174e..09f4ee8 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/MetaConfigurationReader.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/MetaConfigurationReader.java
@@ -18,8 +18,8 @@
*/
package org.apache.tamaya.metamodel.spi;
+import org.apache.tamaya.format.ConfigurationData;
import org.apache.tamaya.spi.ConfigurationBuilder;
-import org.w3c.dom.Document;
/**
* Reader that reads getMeta configuration from the getMeta configuration XML source.
@@ -28,12 +28,12 @@ import org.w3c.dom.Document;
public interface MetaConfigurationReader {
/**
- * Reads getMeta-configuration from the given document and configures the current
+ * Reads meta-configuration from the given document and configures the current
* configuration builder. The priority of readers is determined by the priorization policy
* implemented by the {@link org.apache.tamaya.spi.ServiceContext},
- * @param document the getMeta-configuration document
+ * @param metaConfig the meta-configuration data, not null.
* @param configBuilder the context builder to use.
*/
- void read(Document document, ConfigurationBuilder configBuilder);
+ void read(ConfigurationData metaConfig, ConfigurationBuilder configBuilder);
}
diff --git a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.SimpleResolver b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ContextInitializer
similarity index 86%
rename from metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.SimpleResolver
rename to metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ContextInitializer
index b770ed9..3ba83eb 100644
--- a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.SimpleResolver
+++ b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ContextInitializer
@@ -16,5 +16,3 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.metamodel.internal.resolver.JavaResolver
-org.apache.tamaya.metamodel.internal.resolver.PropertiesResolver
\ No newline at end of file
diff --git a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ItemFactory b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ItemFactory
index 951f4b8..9af06cc 100644
--- a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ItemFactory
+++ b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ItemFactory
@@ -16,11 +16,14 @@
# specific language governing permissions and limitations
# under the License.
#
+org.apache.tamaya.metamodel.internal.factories.ClasspathPropertySourceFactory
org.apache.tamaya.metamodel.internal.factories.CLIArgumentsFactory
+org.apache.tamaya.metamodel.internal.factories.EnvironmentVariablesFactory
org.apache.tamaya.metamodel.internal.factories.EnvPropertiesFactory
org.apache.tamaya.metamodel.internal.factories.FilePropertySourceFactory
org.apache.tamaya.metamodel.internal.factories.ResourcePropertySourceFactory
org.apache.tamaya.metamodel.internal.factories.SysPropertiesFactory
+org.apache.tamaya.metamodel.internal.factories.SystemPropertiesFactory
org.apache.tamaya.metamodel.internal.factories.URLPropertySourceFactory
org.apache.tamaya.metamodel.internal.factories.ResourcePropertySourceProviderFactory
diff --git a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader
index 6442e25..d70e7db 100644
--- a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader
+++ b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader
@@ -20,6 +20,5 @@
org.apache.tamaya.metamodel.internal.PropertyFilterReader
org.apache.tamaya.metamodel.internal.PropertyConverterReader
org.apache.tamaya.metamodel.internal.PropertySourceReader
-org.apache.tamaya.metamodel.internal.MetaContextReader
org.apache.tamaya.metamodel.internal.PropertyFilterOrderingReader
org.apache.tamaya.metamodel.internal.PropertySourceOrderingReader
\ No newline at end of file
diff --git a/hjson/src/test/java/org/apache/tamaya/hjson/HJSONFormatIT.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/ImmutableFilterTest.java
similarity index 55%
rename from hjson/src/test/java/org/apache/tamaya/hjson/HJSONFormatIT.java
rename to metamodel/src/test/java/org/apache/tamaya/metamodel/ImmutableFilterTest.java
index 6258fc5..c681fbb 100644
--- a/hjson/src/test/java/org/apache/tamaya/hjson/HJSONFormatIT.java
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/ImmutableFilterTest.java
@@ -16,32 +16,24 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.hjson;
+package org.apache.tamaya.metamodel;
-import org.apache.tamaya.format.ConfigurationFormat;
-import org.apache.tamaya.spi.ServiceContextManager;
+import org.apache.tamaya.spi.PropertyValue;
import org.junit.Test;
-import java.util.List;
-
import static org.assertj.core.api.Assertions.assertThat;
-/**
- * Integration tests for {@link HJSONFormat}.
- */
-public class HJSONFormatIT {
- @Test
- public void jsonFormatCanBeFoundViaServiceLoader() throws Exception {
- List<ConfigurationFormat> formats = ServiceContextManager.getServiceContext()
- .getServices(ConfigurationFormat.class);
- ConfigurationFormat format = null;
- for (ConfigurationFormat f : formats) {
- if (f instanceof HJSONFormat) {
- format = f;
- break;
- }
- }
- assertThat(format).isNotNull();
+public class ImmutableFilterTest {
+
+ @Test
+ public void filterProperty() {
+ ImmutableFilter filter = new ImmutableFilter();
+ PropertyValue val = PropertyValue.createValue("a", "b");
+ PropertyValue filtered = filter.filterProperty(val, null);
+ assertThat(filtered).isNotNull().isEqualTo(val);
+ PropertyValue val2 = PropertyValue.createValue("a", "b2");
+ filtered = filter.filterProperty(val, null);
+ assertThat(filtered).isNotNull().isEqualTo(val);
}
-}
+}
\ No newline at end of file
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/MaskFilterTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/MaskFilterTest.java
new file mode 100644
index 0000000..9d30b49
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/MaskFilterTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.metamodel;
+
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyValue;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class MaskFilterTest {
+
+ @Test
+ public void getSetMatches() {
+ MaskFilter filter = new MaskFilter();
+ filter.setMatches("*.SEC");
+ assertThat(filter.getMatches()).isNotNull().isEqualTo("*.SEC");
+ }
+
+ @Test
+ public void getSetRoles() {
+ MaskFilter filter = new MaskFilter();
+ filter.setRoles("a", "b");
+ assertThat(Arrays.asList("a", "b")).isEqualTo(filter.getRoles());
+
+ filter = new MaskFilter();
+ filter.setRoles(Arrays.asList("a", "b"));
+ assertThat(Arrays.asList("a", "b")).isEqualTo(filter.getRoles());
+ }
+
+ @Test
+ public void getSetMask() {
+ MaskFilter filter = new MaskFilter();
+ filter.setMask("*");
+ assertThat(filter.getMask()).isEqualTo("*");
+ }
+
+ @Test
+ public void setGetFilterAllValues() {
+ MaskFilter filter = new MaskFilter();
+ filter.setFilterAllValues(true);
+ assertThat(filter.isFilterAllValues()).isTrue();
+ }
+
+ @Test
+ public void setGetFilterSingleValues() {
+ MaskFilter filter = new MaskFilter();
+ filter.setFilterSingleValues(true);
+ assertThat(filter.isFilterSingleValues()).isTrue();
+ }
+
+
+ @Test
+ public void filterProperty() {
+ MaskFilter filter = new MaskFilter();
+ filter.setMatches(".*\\.SEC");
+ assertThat(filter.getMatches()).isEqualTo(".*\\.SEC");
+ PropertyValue value = PropertyValue.createValue("foo.SEC", "someValue");
+ PropertyValue filtered = filter.filterProperty(value,
+ new FilterContext(value, Collections.emptyMap(), ConfigurationContext.EMPTY));
+ assertThat(filtered).isNotNull();
+ assertThat(filtered.getValue()).isNotNull().isEqualTo("*****");
+ }
+
+ @Test
+ public void testToString() {
+ MaskFilter filter = new MaskFilter();
+ filter.setMatches(".*\\.SEC");
+ filter.setMask("*****");
+ filter.setFilterSingleValues(true);
+ filter.setMask("123");
+ assertThat(filter.toString()).isEqualTo("MaskFilter{matches='.*\\.SEC', mask='123', roles='[]', filterAllValues='true', " +
+ "filterSingleValues='true'}");
+ }
+}
\ No newline at end of file
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java
index e5d9b94..c984b3e 100644
--- a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java
@@ -22,7 +22,6 @@ import org.apache.tamaya.Configuration;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.metamodel.CachedFilter;
import org.apache.tamaya.metamodel.MetaConfiguration;
-import org.apache.tamaya.metamodel.MetaContext;
import org.apache.tamaya.spi.PropertyConverter;
import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertySource;
@@ -52,7 +51,7 @@ public class IntegrationTest {
@Test
public void testEmptyConfig(){
- Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/empty-config.xml"));
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/empty-config.conf"));
assertThat(config).isNotNull();
assertThat(config.getProperties()).isEmpty();
assertThat(config.getContext().getPropertySources()).isEmpty();
@@ -61,23 +60,8 @@ public class IntegrationTest {
}
@Test
- public void testMetaContextConfig(){
- Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/context-test.xml"));
- assertThat(config).isNotNull();
- assertThat(config.getProperties()).isEmpty();
- assertThat(config.getContext().getPropertyConverters()).isEmpty();
- assertThat(config.getContext().getPropertyFilters()).isEmpty();
- MetaContext ctx = MetaContext.getInstance();
- assertThat(ctx.getProperties()).isNotEmpty();
- assertThat(ctx.getId()).isEqualTo(ctx.getProperty("_id"));
- assertThat("NONE").isEqualTo(ctx.getProperty("app"));
- assertThat("DEV").isEqualTo(ctx.getProperty("stage"));
- assertThat(".").isEqualTo(ctx.getProperty("configdir"));
- }
-
- @Test
public void testDefaultConvertersConfig(){
- Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/default-propertyconverters-test.xml"));
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/default-propertyconverters-test.conf"));
assertThat(config).isNotNull()
.isEqualTo(Configuration.createConfigurationBuilder()
.addDefaultPropertyConverters()
@@ -90,7 +74,7 @@ public class IntegrationTest {
@Test
public void testDefaultPropertySourcesConfig(){
- Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/default-propertysources-test.xml"));
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/default-propertysources-test.conf"));
assertThat(config).isNotNull()
.isEqualTo(Configuration.createConfigurationBuilder()
.addDefaultPropertySources().build());
@@ -102,7 +86,7 @@ public class IntegrationTest {
@Test
public void testDefaultPropertyFiltersConfig(){
- Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/default-propertyfilters-test.xml"));
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/default-propertyfilters-test.conf"));
assertThat(config).isNotNull()
.isEqualTo(Configuration.createConfigurationBuilder()
.addDefaultPropertyFilters().build());
@@ -114,7 +98,7 @@ public class IntegrationTest {
@Test
public void testPropertyFiltersConfig(){
- Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertyfilters-test.xml"));
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertyfilters-test.conf"));
assertThat(config).isNotNull();
assertThat(config.getProperties()).isEmpty();
assertThat(config.getContext().getPropertySources()).isEmpty();
@@ -125,7 +109,7 @@ public class IntegrationTest {
@Test
public void testPropertyConvertersConfig(){
- Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertyconverters-test.xml"));
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertyconverters-test.conf"));
assertThat(config).isNotNull();
assertThat(config.getProperties()).isEmpty();
assertThat(config.getContext().getPropertySources()).isEmpty();
@@ -138,7 +122,7 @@ public class IntegrationTest {
@Test
public void testPropertySourcesConfig(){
- Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertysources-test.xml"));
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertysources-test.hocon"));
assertThat(config).isNotNull();
assertThat(config.getProperties()).isNotEmpty();
assertThat(config.getContext().getPropertySources()).isNotEmpty().hasSize(2);
@@ -149,7 +133,7 @@ public class IntegrationTest {
@Test
public void testPropertyFilterConfig(){
- Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertyfilter-config-test.xml"));
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertyfilter-config-test.conf"));
assertThat(config).isNotNull();
assertThat(config.getProperties()).isEmpty();
assertThat(config.getContext().getPropertySources()).isEmpty();
@@ -166,10 +150,10 @@ public class IntegrationTest {
@Test
public void testPropertySourceConfig(){
- Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertysource-config-test.xml"));
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertysources-test.hocon"));
assertThat(config).isNotNull();
- assertThat(config.getProperties()).isEmpty();
- assertThat(config.getContext().getPropertySources()).isNotEmpty().hasSize(1);
+ assertThat(config.getProperties()).isNotEmpty();
+ assertThat(config.getContext().getPropertySources()).isNotEmpty().hasSize(2);
assertThat(config.getContext().getPropertyConverters()).isEmpty();
assertThat(config.getContext().getPropertyFilters()).isEmpty();
PropertySource ps = config.getContext().getPropertySources().get(0);
@@ -183,7 +167,7 @@ public class IntegrationTest {
@Test
public void testPropertyConverterConfig(){
- Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertyconverter-config-test.xml"));
+ Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertyconverter-config-test.conf"));
assertThat(config).isNotNull();
assertThat(config.getProperties()).isEmpty();
assertThat(config.getContext().getPropertySources()).isEmpty();
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactoryTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactoryTest.java
index 0c144a8..2b0f7f2 100644
--- a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactoryTest.java
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactoryTest.java
@@ -35,7 +35,7 @@ public class CLIArgumentsFactoryTest {
@Test
public void getName() throws Exception {
- assertThat("CLI").isEqualTo(f.getName());
+ assertThat("cli").isEqualTo(f.getName());
}
@Test
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolverTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolverTest.java
index 3292601..a7acbb6 100644
--- a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolverTest.java
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolverTest.java
@@ -41,8 +41,8 @@ public class JavaResolverTest {
@Test
public void evaluateDirect() throws Exception {
assertThat("createValue").isEqualTo(r.evaluate("\"createValue\""));
- assertThat("1.1").isEqualTo(r.evaluate("1.1"));
- assertThat("1").isEqualTo(r.evaluate("1"));
+ assertThat("1.1").isEqualTo(r.evaluate("\"1.1\""));
+ assertThat(1).isEqualTo(r.evaluate("1"));
}
@Test
@@ -50,16 +50,16 @@ public class JavaResolverTest {
assertThat(System.getProperty("java.version")).isEqualTo(r.evaluate("sys(\"java.version\")"));
String key = System.getenv().keySet().iterator().next();
assertThat(System.getenv(key)).isEqualTo(r.evaluate("env(\""+key+"\")"));
- MetaContext.getInstance().setProperty("foo", "bar");
+ MetaContext.getInstance().setStringProperty("foo", "bar");
assertThat("bar").isEqualTo(r.evaluate("context(\"foo\")"));
}
@Test
public void evaluateExpression() throws Exception {
- assertThat("true").isEqualTo(r.evaluate("env(\"STAGE\") == null"));
- assertThat("true").isEqualTo(r.evaluate("sys(\"STAGE\") == null"));
+ assertThat(true).isEqualTo(r.evaluate("env(\"STAGE\") == null"));
+ assertThat(true).isEqualTo(r.evaluate("sys(\"STAGE\") == null"));
System.setProperty("STAGE", "DEV2");
- assertThat("false").isEqualTo(r.evaluate("sys(\"STAGE\") == null"));
+ assertThat(false).isEqualTo(r.evaluate("sys(\"STAGE\") == null"));
System.setProperty("STAGE", "DEV2");
assertThat("DEV2").isEqualTo(r.evaluate("sys(\"STAGE\") == null?env(\"STAGE\"):sys(\"STAGE\")"));
assertThat("DEV2").isEqualTo(r.evaluate("if(sys(\"STAGE\") == null)return env(\"STAGE\"); else return sys(\"STAGE\");"));
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/LoggingReader.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/LoggingReader.java
deleted file mode 100644
index ec8bd89..0000000
--- a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/LoggingReader.java
+++ /dev/null
@@ -1,76 +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.metamodel.internal.resolver;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
-import org.apache.tamaya.spi.ConfigurationBuilder;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.StringReader;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Timer;
-import java.util.TimerTask;
-
-/**
- * Created by atsticks on 01.05.17.
- */
-public class LoggingReader implements MetaConfigurationReader{
-
- private static final JavaResolver RESOLVER = new JavaResolver();
-
- @Override
- public void read(final Document document, ConfigurationBuilder configBuilder) {
- new Timer(true).schedule(new TimerTask() {
- @Override
- public void run() {
- Map<String, Object> meta = new HashMap<>();
- meta.put("context", Configuration.current().getContext());
- meta.put("config", Configuration.current());
- NodeList nodeList = document.getDocumentElement().getElementsByTagName("context");
- for(int i=0;i<nodeList.getLength();i++){
- Node node = nodeList.item(i);
- if(node.getNodeName().equals("log")){
- String expression = node.getTextContent();
- BufferedReader reader = new BufferedReader(new StringReader(expression));
- String line = null;
- try {
- line = reader.readLine();
- while(line!=null){
- Object res = RESOLVER.evaluate(line);
- if(res!=null) {
- System.out.println(res);
- }
- line = reader.readLine();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }, 10000L);
- }
-
-}
diff --git a/metamodel/src/test/resources/IntegrationTests/propertysources-test.xml b/metamodel/src/test/resources/IntegrationTests/default-propertyconverters-test.conf
similarity index 81%
rename from metamodel/src/test/resources/IntegrationTests/propertysources-test.xml
rename to metamodel/src/test/resources/IntegrationTests/default-propertyconverters-test.conf
index 831da19..14d7696 100644
--- a/metamodel/src/test/resources/IntegrationTests/propertysources-test.xml
+++ b/metamodel/src/test/resources/IntegrationTests/default-propertyconverters-test.conf
@@ -1,4 +1,3 @@
-<!--
// 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
@@ -15,11 +14,9 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-// -->
-<configuration>
- <property-sources>
- <org.apache.tamaya.metamodel.ext.MyPropertySource/>
- <sys-properties />
- </property-sources>
-</configuration>
+converters: [
+ {
+ type: defaults
+ }
+]
diff --git a/metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.xml b/metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.conf
similarity index 87%
copy from metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.xml
copy to metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.conf
index 199f04f..aba6147 100644
--- a/metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.xml
+++ b/metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.conf
@@ -1,4 +1,3 @@
-<!--
// 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
@@ -15,12 +14,10 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-// -->
-<configuration>
+filters: [
+ {
+ type: defaults
+ }
+]
- <property-filters>
- <defaults/>
- </property-filters>
-
-</configuration>
diff --git a/metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.xml b/metamodel/src/test/resources/IntegrationTests/default-propertysources-test.conf
similarity index 87%
copy from metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.xml
copy to metamodel/src/test/resources/IntegrationTests/default-propertysources-test.conf
index 199f04f..859b02a 100644
--- a/metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.xml
+++ b/metamodel/src/test/resources/IntegrationTests/default-propertysources-test.conf
@@ -1,4 +1,3 @@
-<!--
// 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
@@ -15,12 +14,8 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-// -->
-<configuration>
+sources: [
+ { type: defaults }
+]
- <property-filters>
- <defaults/>
- </property-filters>
-
-</configuration>
diff --git a/metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.xml b/metamodel/src/test/resources/IntegrationTests/empty-config.conf
similarity index 87%
rename from metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.xml
rename to metamodel/src/test/resources/IntegrationTests/empty-config.conf
index 199f04f..1abc8b7 100644
--- a/metamodel/src/test/resources/IntegrationTests/default-propertyfilters-test.xml
+++ b/metamodel/src/test/resources/IntegrationTests/empty-config.conf
@@ -1,4 +1,3 @@
-<!--
// 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
@@ -15,12 +14,8 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-// -->
-<configuration>
- <property-filters>
- <defaults/>
- </property-filters>
-</configuration>
+// This is an empty config, which results in an empty and unusable configuration. -->
+
diff --git a/metamodel/src/test/resources/IntegrationTests/context-test.xml b/metamodel/src/test/resources/IntegrationTests/propertyconverter-config-test.conf
similarity index 68%
rename from metamodel/src/test/resources/IntegrationTests/context-test.xml
rename to metamodel/src/test/resources/IntegrationTests/propertyconverter-config-test.conf
index 2b7ffb4..8382d94 100644
--- a/metamodel/src/test/resources/IntegrationTests/context-test.xml
+++ b/metamodel/src/test/resources/IntegrationTests/propertyconverter-config-test.conf
@@ -1,4 +1,3 @@
-<!--
// 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
@@ -15,15 +14,17 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-// -->
-<configuration>
- <!-- Context is evaluated first. -->
- <context>
- <stage>${properties:system:STAGE?default=DEV}</stage>
- <configdir>${properties:system:configdir?default=.}</configdir>
- <app>${properties:system:APP?default=NONE}</app>
- <context>${java:java.util.UUID.randomUUID()}</context>
- </context>
-
-</configuration>
+converters: [
+ {
+ class: org.apache.tamaya.metamodel.ext.MyConverter
+ targetType: java.lang.String
+ properties: {
+ attrValue: attrValue1
+ overrideValue: overrideValue1
+ name: my-converter-name
+ elemValue: elemValue1
+ overrideValue: overrideValue2
+ }
+ }
+]
diff --git a/metamodel/src/test/resources/IntegrationTests/propertyconverter-config-test.xml b/metamodel/src/test/resources/IntegrationTests/propertyconverter-config-test.xml
deleted file mode 100644
index 485ac8b..0000000
--- a/metamodel/src/test/resources/IntegrationTests/propertyconverter-config-test.xml
+++ /dev/null
@@ -1,32 +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.
-// -->
-<configuration>
-
- <property-converters>
- <org.apache.tamaya.metamodel.ext.MyConverter targetType="java.lang.String"
- attrValue="attrValue1"
- overrideValue="overrideValue1">
- <name>my-converter-name</name>
- <elemValue>elemValue1</elemValue>
- <overrideValue>overrideValue2</overrideValue>
- </org.apache.tamaya.metamodel.ext.MyConverter>
- </property-converters>
-
-</configuration>
-
diff --git a/metamodel/src/test/resources/IntegrationTests/empty-config.xml b/metamodel/src/test/resources/IntegrationTests/propertyconverters-test.conf
similarity index 85%
rename from metamodel/src/test/resources/IntegrationTests/empty-config.xml
rename to metamodel/src/test/resources/IntegrationTests/propertyconverters-test.conf
index 42faaed..a94e6bf 100644
--- a/metamodel/src/test/resources/IntegrationTests/empty-config.xml
+++ b/metamodel/src/test/resources/IntegrationTests/propertyconverters-test.conf
@@ -1,4 +1,3 @@
-<!--
// 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
@@ -15,10 +14,11 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-// -->
-<configuration>
- <!-- This is an empty config, which results in an empty and unusable configuration. -->
-
-</configuration>
+converters: [
+ {
+ class: org.apache.tamaya.metamodel.ext.MyConverter
+ targetType: java.lang.String
+ }
+]
diff --git a/metamodel/src/test/resources/IntegrationTests/propertyconverters-test.xml b/metamodel/src/test/resources/IntegrationTests/propertyconverters-test.xml
deleted file mode 100644
index fe47b84..0000000
--- a/metamodel/src/test/resources/IntegrationTests/propertyconverters-test.xml
+++ /dev/null
@@ -1,30 +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.
-// -->
-<configuration>
-
- <!-- combinationPolicy class="" / -->
-
- <!-- Configuration definition. -->
-
- <property-converters>
- <org.apache.tamaya.metamodel.ext.MyConverter targetType="java.lang.String"/>
- </property-converters>
-
-</configuration>
-
diff --git a/metamodel/src/test/resources/IntegrationTests/default-propertysources-test.xml b/metamodel/src/test/resources/IntegrationTests/propertyfilter-config-test.conf
similarity index 70%
rename from metamodel/src/test/resources/IntegrationTests/default-propertysources-test.xml
rename to metamodel/src/test/resources/IntegrationTests/propertyfilter-config-test.conf
index a7270ec..0d75331 100644
--- a/metamodel/src/test/resources/IntegrationTests/default-propertysources-test.xml
+++ b/metamodel/src/test/resources/IntegrationTests/propertyfilter-config-test.conf
@@ -1,4 +1,3 @@
-<!--
// 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
@@ -15,15 +14,17 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-// -->
-<configuration>
- <!-- combinationPolicy class="" / -->
- <!-- Configuration definition. -->
-
- <property-sources>
- <defaults />
- </property-sources>
-
-</configuration>
+filters: [
+ {
+ class: org.apache.tamaya.metamodel.ext.MyFilter
+ properties: {
+ attrValue: attrValue1
+ overrideValue: overrideValue1
+ name: my-filter-name
+ elemValue: elemValue1
+ overrideValue: overrideValue2
+ }
+ }
+]
diff --git a/metamodel/src/test/resources/IntegrationTests/propertyfilter-config-test.xml b/metamodel/src/test/resources/IntegrationTests/propertyfilter-config-test.xml
deleted file mode 100644
index 71c1b3a..0000000
--- a/metamodel/src/test/resources/IntegrationTests/propertyfilter-config-test.xml
+++ /dev/null
@@ -1,30 +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.
-// -->
-<configuration>
-
- <property-filters>
- <org.apache.tamaya.metamodel.ext.MyFilter attrValue="attrValue1" overrideValue="overrideValue1">
- <name>my-filter-name</name>
- <elemValue>elemValue1</elemValue>
- <overrideValue>overrideValue2</overrideValue>
- </org.apache.tamaya.metamodel.ext.MyFilter>
- </property-filters>
-
-</configuration>
-
diff --git a/metamodel/src/test/resources/IntegrationTests/propertyfilters-test.xml b/metamodel/src/test/resources/IntegrationTests/propertyfilters-test.conf
similarity index 83%
rename from metamodel/src/test/resources/IntegrationTests/propertyfilters-test.xml
rename to metamodel/src/test/resources/IntegrationTests/propertyfilters-test.conf
index c1f4ee4..cff412a 100644
--- a/metamodel/src/test/resources/IntegrationTests/propertyfilters-test.xml
+++ b/metamodel/src/test/resources/IntegrationTests/propertyfilters-test.conf
@@ -1,4 +1,3 @@
-<!--
// 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
@@ -15,12 +14,16 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-// -->
-<configuration>
- <property-filters>
- <Cached timeout="30000" maxSize="300" matches="cached.*"/>
- </property-filters>
+filters: [
+ {
+ type: cached
+ properties: {
+ timeout: 30000
+ maxSize: 300
+ matches: "cached.*"
+ }
-</configuration>
+ }
+]
diff --git a/metamodel/src/test/resources/IntegrationTests/propertysource-config-test.xml b/metamodel/src/test/resources/IntegrationTests/propertysource-config-test.xml
deleted file mode 100644
index 28710d4..0000000
--- a/metamodel/src/test/resources/IntegrationTests/propertysource-config-test.xml
+++ /dev/null
@@ -1,31 +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.
-// -->
-<configuration>
-
- <property-sources>
- <org.apache.tamaya.metamodel.ext.MyPropertySource
- attrValue="attrValue1" overrideValue="overrideValue1">
- <name2>my-source-name</name2>
- <elemValue>elemValue1</elemValue>
- <overrideValue>overrideValue2</overrideValue>
- </org.apache.tamaya.metamodel.ext.MyPropertySource>
- </property-sources>
-
-</configuration>
-
diff --git a/metamodel/src/test/resources/IntegrationTests/default-propertyconverters-test.xml b/metamodel/src/test/resources/IntegrationTests/propertysources-test.hocon
similarity index 72%
rename from metamodel/src/test/resources/IntegrationTests/default-propertyconverters-test.xml
rename to metamodel/src/test/resources/IntegrationTests/propertysources-test.hocon
index 91252cf..424c89d 100644
--- a/metamodel/src/test/resources/IntegrationTests/default-propertyconverters-test.xml
+++ b/metamodel/src/test/resources/IntegrationTests/propertysources-test.hocon
@@ -1,4 +1,3 @@
-<!--
// 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
@@ -15,17 +14,17 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-// -->
-<configuration>
- <!-- combinationPolicy class="" / -->
-
- <!-- Configuration definition. -->
-
- <property-converters>
- <!--<converter type="AllInOneConverter"/>-->
- <defaults/>
- </property-converters>
-
-</configuration>
+sources: [
+ {
+ class: org.apache.tamaya.metamodel.ext.MyPropertySource
+ properties: {
+ name2: "my-source-name"
+ attrValue: attrValue1
+ elemValue: elemValue1
+ overrideValue: overrideValue2
+ }
+ }
+ { type: sys-properties }
+]
diff --git a/metamodel/src/test/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader b/metamodel/src/test/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader
index ace072c..3ba83eb 100644
--- a/metamodel/src/test/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader
+++ b/metamodel/src/test/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader
@@ -16,4 +16,3 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.metamodel.internal.resolver.LoggingReader
\ No newline at end of file
diff --git a/metamodel/src/test/resources/tamaya-config.conf b/metamodel/src/test/resources/tamaya-config.conf
new file mode 100644
index 0000000..948ddc8
--- /dev/null
+++ b/metamodel/src/test/resources/tamaya-config.conf
@@ -0,0 +1,124 @@
+# 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.
+sources: [
+ {
+ type: env-properties
+ filters: [
+ {
+ type: mapped
+ properties: {
+ target: "ENV."
+ }
+ }
+ {
+ type: mask
+ properties: {
+ mask: "*****"
+ matches: SEC_
+ }
+ }
+ ]
+ }
+ {
+ type: sys-properties
+ filters: [
+ { type: immutable }
+ ]
+ }
+ {
+ type: file
+ properties: {
+ file: config.json
+ }
+ refreshable: true
+ }
+ {
+ type: file
+ properties: {
+ file: config.xml
+ format: xml-properties
+ }
+ refreshable: true
+ }
+ {
+ type: file
+ properties: {
+ file: config.xml
+ format: xml-properties
+ }
+ refreshable: true
+ }
+ {
+ type: resource
+ properties: {
+ resources: /META-INF/application-config.yml
+ }
+ }
+ {
+ class: ch.mypack.MyClassSource
+ refreshable: true
+ }
+ {
+ type: resource
+ properties: {
+ resources: "${context('configdir')}/**/*.json"
+ enabled: "${context('configdir') != null}"
+ }
+ }
+ {
+ type: url
+ properties: {
+ url: "https://www.confdrive.com/cfg/customerId=1234"
+ format: json
+ }
+ refreshable: true
+ filters: [
+ {
+ type: cached
+ properties: {
+ ttl: 30 SECOND
+ }
+ }
+ ]
+ }
+]
+
+filters: [
+ {
+ type: secured
+ properties: {
+ roles: "admin,power-user"
+ matches: "*.secret"
+ policy: HIDE
+ }
+ }
+ {
+ type: cached
+ properties: {
+ timeout: 30000
+ maxSize: 300
+ matches: "cached.*"
+ }
+ }
+]
+
+converters: [
+ { type: default-converters }
+]
+
+
+
diff --git a/metamodel/src/test/resources/tamaya-config.xml b/metamodel/src/test/resources/tamaya-config.xml
index d372249..ccc60eb 100644
--- a/metamodel/src/test/resources/tamaya-config.xml
+++ b/metamodel/src/test/resources/tamaya-config.xml
@@ -18,18 +18,17 @@
// -->
<configuration>
<!-- Context is evaluated first. -->
- <context>
- <stage>${properties:system:STAGE?default=DEV}</stage>
- <configdir>${properties:system:configdir?default=.}</configdir>
- <app>${properties:system.APP?default=NONE}</app>
- <context>${java:java.util.UUID.randomUUID()}</context>
- <company>Trivadis</company>
- <default-formats>yaml,json</default-formats>
- <default-refresh-period>5 SECOND</default-refresh-period>
- </context>
- <context name="APP">
- <application>someAppName</application>
- </context>
+ <context-initializers>
+ <context-initializer></context-initializer>
+ <context-initializer></context-initializer>
+ <!--<configdir>${properties:system:configdir?default=.}</configdir>-->
+ <!--<app>${properties:system.APP?default=NONE}</app>-->
+ <!--<context>${java:java.util.UUID.randomUUID()}</context>-->
+ <!--<company>Trivadis</company>-->
+ <!--<default-formats>yaml,json</default-formats>-->
+ <!--<default-refresh-period>5 SECOND</default-refresh-period>-->
+ </context-initializers>
+
<!-- combinationPolicy class="" / -->
diff --git a/pom.xml b/pom.xml
index bcbeb9a..0e8bcae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -839,7 +839,6 @@ under the License.
<module>vertx</module>
<module>configjsr</module>
<module>documentation</module>
- <module>hjson</module>
<!-- Once the API is officially available ... -->
<!-- module>configjsr</module-->
</modules>
diff --git a/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java b/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java
index 92afd1d..60e5ff8 100644
--- a/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java
+++ b/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java
@@ -54,7 +54,7 @@ public abstract class BaseRemotePropertySource implements PropertySource{
@Override
public Map<String, PropertyValue> getProperties() {
- return PropertyValue.map(properties, getName());
+ return PropertyValue.mapProperties(properties, getName());
}
/**
diff --git a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfigValidationDocumentationReader.java b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfigValidationDocumentationReader.java
index b09295c..5346cb6 100644
--- a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfigValidationDocumentationReader.java
+++ b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfigValidationDocumentationReader.java
@@ -72,7 +72,7 @@ public class ConfigValidationDocumentationReader implements ClassloaderAware {
private void loadValidations(DocumentedArea docArea, List<ConfigValidator> result) {
result.add(new AreaValidator(docArea));
// for(DocumentedProperty propDoc:docArea.getPropertiesSorted()){
-// result.add(new PropertyValidator(propDoc));
+// result.addPropertyValue(new PropertyValidator(propDoc));
// }
// for(DocumentedArea area:docArea.getAreasSorted()){
// loadValidations(area, result);
diff --git a/vertx/pom.xml b/vertx/pom.xml
index 6d9a15f..dae922f 100644
--- a/vertx/pom.xml
+++ b/vertx/pom.xml
@@ -34,7 +34,7 @@
<packaging>jar</packaging>
<properties>
- <vertx.version>3.3.0</vertx.version>
+ <vertx.version>3.6.3</vertx.version>
</properties>
<dependencies>
diff --git a/vertx/src/main/java/org/apache/tamaya/vertx/ConfiguredJavaVerticleFactory.java b/vertx/src/main/java/org/apache/tamaya/vertx/ConfiguredVerticleFactory.java
similarity index 87%
rename from vertx/src/main/java/org/apache/tamaya/vertx/ConfiguredJavaVerticleFactory.java
rename to vertx/src/main/java/org/apache/tamaya/vertx/ConfiguredVerticleFactory.java
index efb3c70..b5051da 100644
--- a/vertx/src/main/java/org/apache/tamaya/vertx/ConfiguredJavaVerticleFactory.java
+++ b/vertx/src/main/java/org/apache/tamaya/vertx/ConfiguredVerticleFactory.java
@@ -22,11 +22,12 @@ import io.vertx.core.Verticle;
import io.vertx.core.impl.verticle.CompilingClassLoader;
import io.vertx.core.spi.VerticleFactory;
import org.apache.tamaya.inject.ConfigurationInjection;
+import org.apache.tamaya.inject.ConfigurationInjector;
/**
* Verticle factory that produces Java verticles that are configured with the Tamaya injection API.
*/
-public class ConfiguredJavaVerticleFactory implements VerticleFactory{
+public class ConfiguredVerticleFactory implements VerticleFactory{
@Override
public String prefix() {
@@ -50,8 +51,8 @@ public class ConfiguredJavaVerticleFactory implements VerticleFactory{
clazz = classLoader.loadClass(verticleName);
}
- Verticle instance = (Verticle)clazz.newInstance();
- ConfigurationInjection.getConfigurationInjector().configure(instance);
+ Verticle instance = (Verticle)clazz.getConstructor().newInstance();
+ ConfigurationInjector.getInstance(classLoader).configure(instance);
return instance;
}
}
diff --git a/vertx/src/main/java/org/apache/tamaya/vertx/TamayaConfigurationProducer.java b/vertx/src/main/java/org/apache/tamaya/vertx/TamayaConfigurationProducer.java
index d8af31e..0ee0aeb 100644
--- a/vertx/src/main/java/org/apache/tamaya/vertx/TamayaConfigurationProducer.java
+++ b/vertx/src/main/java/org/apache/tamaya/vertx/TamayaConfigurationProducer.java
@@ -28,6 +28,7 @@ import io.vertx.core.json.JsonObject;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.functions.ConfigurationFunctions;
import org.apache.tamaya.inject.ConfigurationInjection;
+import org.apache.tamaya.inject.ConfigurationInjector;
import org.apache.tamaya.inject.api.Config;
import java.util.Map;
@@ -123,7 +124,7 @@ public class TamayaConfigurationProducer extends AbstractConfiguredVerticle{
if(o==null){
h.fail(HttpResponseStatus.BAD_REQUEST.code(), "Required createObject to configure is missing.");
}else {
- ConfigurationInjection.getConfigurationInjector().configure(o);
+ ConfigurationInjector.getInstance().configure(o);
h.reply("OK");
}
});
diff --git a/vertx/src/main/resources/META-INF/services/io.vertx.core.spi.VerticleFactory b/vertx/src/main/resources/META-INF/services/io.vertx.core.spi.VerticleFactory
index b335f38..fcdf969 100644
--- a/vertx/src/main/resources/META-INF/services/io.vertx.core.spi.VerticleFactory
+++ b/vertx/src/main/resources/META-INF/services/io.vertx.core.spi.VerticleFactory
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.vertx.ConfiguredJavaVerticleFactory
\ No newline at end of file
+org.apache.tamaya.vertx.ConfiguredVerticleFactory
\ No newline at end of file
diff --git a/vertx/src/test/java/org/apache/tamaya/vertx/ConfigVerticleTest.java b/vertx/src/test/java/org/apache/tamaya/vertx/ConfigVerticleTest.java
index 6033c53..e19fe9c 100644
--- a/vertx/src/test/java/org/apache/tamaya/vertx/ConfigVerticleTest.java
+++ b/vertx/src/test/java/org/apache/tamaya/vertx/ConfigVerticleTest.java
@@ -60,7 +60,6 @@ public class ConfigVerticleTest {
}
@Test
-
public void testSingle(final TestContext testContext) {
final Async async = testContext.async();
vertxContext.vertx().eventBus().send(TamayaConfigurationProducer.DEFAULT_CONFIG_GET_SINGLE_ADDRESS,