You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2016/12/12 16:13:04 UTC
[1/5] incubator-tamaya-sandbox git commit: Added tests and bugfixes
for Tamaya OSGI support.
Repository: incubator-tamaya-sandbox
Updated Branches:
refs/heads/master ff8e47c57 -> afc19d0e7
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/src/main/java/org/apache/tamaya/osgi/TamayaConfigurationImpl.java
----------------------------------------------------------------------
diff --git a/osgi/src/main/java/org/apache/tamaya/osgi/TamayaConfigurationImpl.java b/osgi/src/main/java/org/apache/tamaya/osgi/TamayaConfigurationImpl.java
deleted file mode 100644
index eef01d7..0000000
--- a/osgi/src/main/java/org/apache/tamaya/osgi/TamayaConfigurationImpl.java
+++ /dev/null
@@ -1,127 +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.osgi;
-
-import java.io.IOException;
-import java.util.*;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.functions.PropertyMatcher;
-import org.apache.tamaya.functions.ConfigurationFunctions;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-
-/**
- * Tamaya based implementation of an OSGI {@link Configuration}.
- */
-public class TamayaConfigurationImpl implements Configuration {
- private static final Logger LOG = Logger.getLogger(TamayaConfigurationImpl.class.getName());
- private final String pid;
- private final String factoryPid;
- private Map<String, String> properties = new HashMap<>();
- private org.apache.tamaya.Configuration config;
-
- /**
- * Constructor.
- * @param confPid the OSGI pid
- * @param factoryPid the factory pid
- * @param configRootMapper the mapper that maps the pids to a tamaya root section.
- * @param parent the (optional delegating parent, used as default).
- */
- TamayaConfigurationImpl(String confPid, String factoryPid, OSGIConfigRootMapper configRootMapper,
- ConfigurationAdmin parent) {
- this.pid = confPid;
- this.factoryPid = factoryPid;
- if(parent!=null){
- try {
- Dictionary<String, Object> conf = parent.getConfiguration(confPid, factoryPid).getProperties();
- if(conf!=null) {
- LOG.info("Configuration: Adding default parameters from parent: " + parent.getClass().getName());
- Enumeration<String> keys = conf.keys();
- while (keys.hasMoreElements()) {
- String key = keys.nextElement();
- this.properties.put(key, conf.get(key).toString());
- }
- }
- } catch (IOException e) {
- LOG.log(Level.WARNING, "Error reading parent OSGI config.", e);
- }
- }
- this.config = ConfigurationProvider.getConfiguration();
- final String rootKey = configRootMapper.getTamayaConfigRoot(pid, factoryPid);
- LOG.info("Configuration: Evaluating Tamaya configuration for '" + rootKey + "'.");
- this.properties.putAll(
- config.with(ConfigurationFunctions.section(rootKey, true)).getProperties());
- }
-
- @Override
- public String getPid() {
- return pid;
- }
-
- @Override
- public Dictionary<String, Object> getProperties() {
- return new Hashtable<String, Object>(properties);
- }
-
- @Override
- public void update(Dictionary<String, ?> properties) throws IOException {
- throw new UnsupportedOperationException("Nuatability not yet supported.");
- // ConfigChangeProvider.createChangeRequest(this.config)
- }
-
- @Override
- public void delete() throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public String getFactoryPid() {
- return factoryPid;
- }
-
- @Override
- public void update() throws IOException {
- this.config = ConfigurationProvider.getConfiguration();
- this.properties = config.with(ConfigurationFunctions.filter(new PropertyMatcher() {
- @Override
- public boolean test(String key, String value) {
-// TODO define name space / SPI
- return false;
- }
- })).getProperties();
- }
-
- @Override
- public void setBundleLocation(String location) {
- }
-
- @Override
- public String getBundleLocation() {
- return null;
- }
-
- @Override
- public long getChangeCount() {
- return 0;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/osgi/src/test/resources/META-INF/javaconfiguration.properties b/osgi/src/test/resources/META-INF/javaconfiguration.properties
deleted file mode 100644
index 0f09ce9..0000000
--- a/osgi/src/test/resources/META-INF/javaconfiguration.properties
+++ /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.
-#
-[bundle:tamaya]my.testProperty=success!
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/osgi/src/test/resources/arquillian.xml b/osgi/src/test/resources/arquillian.xml
deleted file mode 100644
index a4c885a..0000000
--- a/osgi/src/test/resources/arquillian.xml
+++ /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 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.
--->
-<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
-
- <container qualifier="osgi" default="true">
- <configuration>
- <property name="frameworkProperties">src/test/resources/felix.properties</property>
- </configuration>
- </container>
-</arquillian>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/src/test/resources/felix.properties
----------------------------------------------------------------------
diff --git a/osgi/src/test/resources/felix.properties b/osgi/src/test/resources/felix.properties
deleted file mode 100644
index 4630fa2..0000000
--- a/osgi/src/test/resources/felix.properties
+++ /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.
-#
-# org.osgi.service.cm;org.apache.felix.cm;org.apache.tamaya;org.apache.tamaya.spi;
-org.osgi.framework.bootdelegation=org.apache.tamaya,org.apache.tamaya.osgi,org.apache.tamaya.osgi.test
-felix.log.level=4 #debug logging
-# felix.auto.deploy.dir=../test-bundles
-org.osgi.framework.storage=target/felix-cache
-felix.fileinstall.dir=./test-bundles
\ No newline at end of file
[5/5] incubator-tamaya-sandbox git commit: Added tests for OSGI
support,
simplified OSGI support. Implemented base functionality for metamodel support,
including first testing.
Posted by an...@apache.org.
Added tests for OSGI support, simplified OSGI support.
Implemented base functionality for metamodel support, including first testing.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/afc19d0e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/afc19d0e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/afc19d0e
Branch: refs/heads/master
Commit: afc19d0e74cde66603dc3d440d6799b917efb815
Parents: f0dfa86
Author: anatole <an...@apache.org>
Authored: Mon Dec 12 17:12:06 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Dec 12 17:12:06 2016 +0100
----------------------------------------------------------------------
metamodel/pom.xml | 7 +
.../org/apache/tamaya/metamodel/Context.java | 171 -----
.../metamodel/FilteredPropertySource.java | 166 +++++
.../tamaya/metamodel/MetaConfiguration.java | 144 ++++
.../apache/tamaya/metamodel/MetaContext.java | 330 ++++++++++
.../apache/tamaya/metamodel/Refreshable.java | 32 +
.../metamodel/RefreshablePropertySource.java | 150 +++++
.../RefreshablePropertySourceProvider.java | 106 +++
.../tamaya/metamodel/dsl/MetaConfiguration.java | 122 ----
.../metamodel/dsl/TamayaConfigurator.java | 234 -------
.../metamodel/dsl/WrappedPropertySource.java | 127 ----
.../DSLLoadingConfigurationProviderSpi.java | 81 ---
.../NamedDSLPropertySourceProvider.java | 53 --
.../ResourceDSLPropertySourceProvider.java | 82 ---
.../internal/CombinationPolicyReader.java | 61 ++
.../internal/ComponentConfigurator.java | 87 +++
.../metamodel/internal/ComponentFactory.java | 112 ++++
.../metamodel/internal/ContextReader.java | 66 ++
.../DSLLoadingConfigurationProviderSpi.java | 114 ++++
...efaultRefreshablePropertySourceProvider.java | 72 --
.../metamodel/internal/FactoryManager.java | 140 ----
.../internal/PropertyConverterReader.java | 88 +++
.../internal/PropertyFilterOrderingReader.java | 63 ++
.../internal/PropertyFilterReader.java | 83 +++
.../internal/PropertySourceOrderingReader.java | 64 ++
.../internal/PropertySourceReader.java | 103 +++
.../tamaya/metamodel/internal/Refreshable.java | 37 --
.../tamaya/metamodel/internal/SourceConfig.java | 466 ++++++-------
.../internal/factories/CLIArgumentsFactory.java | 47 ++
.../factories/EnvPropertiesFactory.java | 46 ++
.../factories/FilePropertySourceFactory.java | 77 +++
.../ResourcePropertySourceFactory.java | 64 ++
.../ResourcePropertySourceProviderFactory.java | 115 ++++
.../factories/SysPropertiesFactory.java | 46 ++
.../factories/URLPropertySourceFactory.java | 152 +++++
.../tamaya/metamodel/spi/ItemFactory.java | 51 ++
.../metamodel/spi/ItemFactoryManager.java | 145 ++++
.../metamodel/spi/MetaConfigurationReader.java | 8 +-
.../metamodel/spi/PropertySourceFactory.java | 48 --
.../spi/PropertySourceProviderFactory.java | 49 --
...maya.metamodel.spi.DSLPropertySourceProvider | 20 -
.../org.apache.tamaya.metamodel.spi.ItemFactory | 26 +
...tamaya.metamodel.spi.MetaConfigurationReader | 26 +
...g.apache.tamaya.spi.ConfigurationProviderSpi | 3 +-
.../resources/IntegrationTests/empty-config.xml | 24 +
metamodel/src/test/resources/tamaya-config.xml | 73 ++-
pom.xml | 657 ++++++++++++++++++-
47 files changed, 3529 insertions(+), 1509 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/pom.xml
----------------------------------------------------------------------
diff --git a/metamodel/pom.xml b/metamodel/pom.xml
index 13c5c47..a103441 100644
--- a/metamodel/pom.xml
+++ b/metamodel/pom.xml
@@ -71,6 +71,13 @@
<artifactId>tamaya-formats</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-resources</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
<!--<dependency>-->
<!--<groupId>org.apache.tamaya.ext</groupId>-->
<!--<artifactId>tamaya-json</artifactId>-->
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/Context.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/Context.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/Context.java
deleted file mode 100644
index b4b65d2..0000000
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/Context.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.metamodel;
-
-import java.util.Collections;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Class managing the configuration system's shared 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.
- */
-public final class Context {
-
- private static final ThreadLocal<Context> THREAD_CONTEXT = new ThreadLocal<Context>(){
- @Override
- protected Context initialValue() {
- return new Context();
- }
- };
-
- private final Map<String,String> properties = new ConcurrentHashMap<>();
-
- /**
- * Access the thread-based context. If no such context
- * exists a new one will be created.
- * @return the corresponding context, never null.
- */
- public static Context getThreadInstance(){
- return THREAD_CONTEXT.get();
- }
-
- /**
- * Access the current context, which actually is the current context, combined with the thread based
- * context (overriding).
- * @return the corresponding context, never null.
- */
- public Context getCurrentInstance(){
- return this.combineWith(THREAD_CONTEXT.get());
- }
-
- /**
- * Combine this context with the other contexts given.
- * @param contexts the context to merge with this context.
- * @return the newly created Context.
- */
- public Context combineWith(Context... contexts) {
- Context newContext = new Context();
- newContext.properties.putAll(getProperties());
- for(Context ctx:contexts) {
- newContext.properties.putAll(ctx.getProperties());
- }
- return newContext;
- }
-
- /**
- * Access the given context property.
- * @param key the key, not null
- * @return the value, or null.
- */
- public String getProperty(String key){
- return getProperty(key, null);
- }
-
- /**
- * Access the given context property.
- * @param key the key, not the default value.
- * @param defaultValue the default value to be returned, if no value is defined.
- * @return the value, default value or null.
- */
- public String getProperty(String key, String defaultValue){
- String value = this.properties.get(key);
- if(value==null){
- return defaultValue;
- }
- return value;
- }
-
- /**
- * Sets the given context property.
- * @param key the key, not null.
- * @param value the value, not null.
- * @return the porevious value, or null.
- */
- public String setProperty(String key, String value){
- return this.properties.put(key,value);
- }
-
- /**
- * Sets the given property unless there is already a value defined.
- * @param key the key, not null.
- * @param value the value, not null.
- */
- public void setPropertyIfAbsent(String key, String value){
- String prev = this.properties.get(key);
- if(prev==null){
- this.properties.put(key, prev);
- }
- }
-
- /**
- * Adds all properties given, overriding any existing properties.
- * @param properties the properties, not null.
- */
- public void setProperties(Map<String,String> properties){
- this.properties.putAll(properties);
- }
-
- /**
- * 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){
- for(String key:keys) {
- if (getProperty(key, null) == null) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Access all the current context properties.
- * @return the properties, never null.
- */
- public Map<String,String> getProperties(){
- return Collections.unmodifiableMap(this.properties);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof Context)) return false;
-
- Context context = (Context) o;
-
- return getProperties().equals(context.getProperties());
-
- }
-
- @Override
- public int hashCode() {
- return getProperties().hashCode();
- }
-
- @Override
- public String toString() {
- return "Context{" +
- properties +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/FilteredPropertySource.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/FilteredPropertySource.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/FilteredPropertySource.java
new file mode 100644
index 0000000..b4f95f5
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/FilteredPropertySource.java
@@ -0,0 +1,166 @@
+/*
+ * 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.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spisupport.BasePropertySource;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Property source that allows filtering on property source level. This class is thread-safe, accesses using or
+ * changing the filter list are synchronized.
+ */
+public final class FilteredPropertySource extends BasePropertySource {
+
+ private PropertySource wrapped;
+ private List<PropertyFilter> filters = new ArrayList<>();
+
+ /**
+ * Constructor used privately. Use {@link #of(PropertySource)} for making a {@link PropertySource} filterable.
+ * @param propertySource the property source to be filtered.
+ */
+ private FilteredPropertySource(PropertySource propertySource){
+ this.wrapped = Objects.requireNonNull(propertySource);
+ }
+
+
+ /**
+ * Wraps a given property source.
+ * @param propertySource the property source to be wrapped.
+ * @return a wrapped property source.
+ */
+ public static FilteredPropertySource of(PropertySource propertySource){
+ if(propertySource instanceof FilteredPropertySource){
+ return (FilteredPropertySource)propertySource;
+ }
+ return new FilteredPropertySource(propertySource);
+ }
+
+ @Override
+ public int getOrdinal() {
+ int ordinalSet = super.getOrdinal();
+ if(ordinalSet == 0){
+ return this.wrapped.getOrdinal();
+ }
+ return ordinalSet;
+ }
+
+ @Override
+ public String getName() {
+ return wrapped.getName();
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ PropertyValue value = wrapped.get(key);
+ if(value != null && value.getValue()!=null){
+ if(filters!=null){
+ String filteredValue = value.getValue();
+ for(PropertyFilter pf:filters){
+ filteredValue = pf.filterProperty(filteredValue, new FilterContext(key, value.getConfigEntries(), true));
+ }
+ if(filteredValue!=null){
+ return PropertyValue.builder(key, filteredValue, getName())
+ .setContextData(value.getConfigEntries()).build();
+ }
+ }
+ }
+ return value;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> wrappedProps = wrapped.getProperties();
+ if(!filters.isEmpty()){
+ Map<String, String> result = new HashMap<>();
+ synchronized (filters) {
+ for (String key : wrappedProps.keySet()) {
+ PropertyValue value = wrapped.get(key);
+ FilterContext filterContext = new FilterContext(key, value.getConfigEntries(), true);
+ String filteredValue = value.getValue();
+ for (PropertyFilter pf : filters) {
+ filteredValue = pf.filterProperty(filteredValue, filterContext);
+ }
+ if (filteredValue != null) {
+ result.putAll(value.getConfigEntries());
+ result.put(key, filteredValue);
+ }
+
+ }
+ }
+ return result;
+ }
+ return wrappedProps;
+ }
+
+ @Override
+ public boolean isScannable() {
+ return wrapped.isScannable();
+ }
+
+ /**
+ * Adds the given filters to this property source.
+ * @param filter the filters, not null.
+ */
+ public void addPropertyFilter(PropertyFilter... filter){
+ synchronized(filters){
+ this.filters.addAll(Arrays.asList(filter));
+ }
+ }
+
+ /**
+ * Removes the given filter, if present.
+ * @param filter the filter to remove, not null.
+ */
+ public void removePropertyFilter(PropertyFilter filter){
+ synchronized(filters){
+ this.filters.remove(filter);
+ }
+ }
+
+ /**
+ * Access the current filters present.
+ * @return a copy of the current filter list.
+ */
+ public List<PropertyFilter> getPropertyFilter(){
+ synchronized (filters){
+ return new ArrayList<>(filters);
+ }
+ }
+
+ @Override
+ public String toString() {
+ synchronized (filters) {
+ return "FilteredPropertySource{" +
+ "\n wrapped=" + wrapped +
+ "\n filters=" + this.filters +
+ "\n base=" + super.toString() +
+ "\n}";
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaConfiguration.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaConfiguration.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaConfiguration.java
new file mode 100644
index 0000000..601c851
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaConfiguration.java
@@ -0,0 +1,144 @@
+/*
+ * 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.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.ServiceContextManager;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Accessor singleton for accessing/loading meta-configuration.
+ */
+public final class MetaConfiguration {
+
+ private static final String CONFIG_RESOURCE = "tamaya-config.xml";
+
+ private static final Logger LOG = Logger.getLogger(MetaConfiguration.class.getName());
+
+ /**
+ * Singleton constructor.
+ */
+ private MetaConfiguration(){}
+
+ /**
+ * Creates a new {@link Configuration} using {@link #createConfiguration(URL)}
+ * and applies it as default configuration using {@link ConfigurationProvider#setConfiguration(Configuration)}.
+ * @return the new configuration instance.
+ */
+ public static void configure(){
+ LOG.info("TAMAYA: Checking for meta-configuration...");
+ URL configFile = getDefaultMetaConfig();
+ if(configFile==null){
+ LOG.warning("TAMAYA: No tamaya-config.xml found, using defaults.");
+ }
+ configure(configFile);
+ }
+
+ /**
+ * Creates a new {@link Configuration} using {@link #createConfiguration(URL)}
+ * and applies it as default configuration using {@link ConfigurationProvider#setConfiguration(Configuration)}.
+ * @param metaConfig URL for loading the {@code tamaya-config.xml} meta-configuration.
+ * @return the new configuration instance.
+ */
+ public static void configure(URL metaConfig){
+ try {
+ // Let readers do their work
+ Configuration config = createConfiguration(metaConfig);
+ ConfigurationProvider.setConfiguration(config);
+ }catch(Exception e){
+ LOG.log(Level.SEVERE, "TAMAYA: Error loading configuration.", e);
+ }
+ }
+
+ private static URL getDefaultMetaConfig() {
+ // 1: check tamaya-config system property
+ String tamayaConfig = System.getProperty("tamaya-config");
+ if(tamayaConfig!=null){
+ File file = new File(tamayaConfig);
+ if(!file.exists() || !file.canRead() || !file.isFile()){
+ LOG.severe("TAMAYA: Not a valid config file: " + tamayaConfig);
+ }else{
+ try {
+ return file.toURI().toURL();
+ } catch (MalformedURLException e) {
+ LOG.severe("TAMAYA: Invalid file name: " + tamayaConfig);
+ }
+ }
+ }
+ return MetaConfiguration.class.getClassLoader().getResource(CONFIG_RESOURCE);
+ }
+
+ /**
+ * Performs initialization of a new configuration
+ * context to the {@link MetaConfigurationReader} instances found in the current
+ * {@link org.apache.tamaya.spi.ServiceContext} and returns the corresponding builder
+ * instance.
+ * @param metaConfig URL for loading the {@code tamaya-config.xml} meta-configuration.
+ * @return a new configuration context builder, never null.
+ * @throws ConfigException If the URL cannot be read.
+ */
+ public static ConfigurationContextBuilder createContextBuilder(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());
+ ConfigurationContextBuilder builder = ConfigurationProvider.getConfigurationContextBuilder();
+ for(MetaConfigurationReader reader: ServiceContextManager.getServiceContext().getServices(
+ MetaConfigurationReader.class
+ )){
+ LOG.fine("TAMAYA: Executing MetaConfig-Reader: " + reader.getClass().getName()+"...");
+ reader.read(document, builder);
+ }
+ return builder;
+ } catch (SAXException | IOException | ParserConfigurationException e) {
+ throw new ConfigException("Cannot read meta-config deom " + metaConfig, e);
+ }
+ }
+
+ /**
+ * Reads the meta-configuration and delegates initialization of the current configuration
+ * context to the {@link MetaConfigurationReader} instances found in the current
+ * {@link org.apache.tamaya.spi.ServiceContext}.
+ * @param metaConfig URL for loading the {@code tamaya-config.xml} meta-configuration.
+ * @return the new configuration instance.
+ */
+ public static Configuration createConfiguration(URL metaConfig){
+ ConfigurationContext context = createContextBuilder(metaConfig).build();
+ return ConfigurationProvider.createConfiguration(context);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
new file mode 100644
index 0000000..4032c03
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
@@ -0,0 +1,330 @@
+/*
+ * 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.functions.Supplier;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.WeakHashMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Class managing the configuration system's shared 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 context are
+ * <ul>
+ * <li>identified by unique names</li>
+ * <li>stackable into a context hierarchy, see {@link #combineWith(MetaContext...)}</li>
+ * <li>optionally be valid only in some contexts or for a limited time, see {@link #isValid()},
+ * {@link #getInstance(String, Supplier)}</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 #getCurrentInstance()}.
+ */
+public final class MetaContext {
+
+ private static final ThreadLocal<MetaContext> THREAD_CONTEXT = new ThreadLocal<MetaContext>(){
+ @Override
+ protected MetaContext initialValue() {
+ return new MetaContext();
+ }
+ };
+
+ private String id;
+
+ private Supplier<Boolean> validSupplier;
+
+ private final Map<String,Value> properties = new ConcurrentHashMap<>();
+
+ private static final Map<String,MetaContext> CONTEXTS = new WeakHashMap<>();
+
+ /**
+ * Access a context by name. Contexts are managed as weak references in this class. If no
+ * such context exists, a new instance is created.
+ * @param contextName the context name, not null.
+ * @return the context instance, never null.
+ */
+ public static MetaContext getInstance(String contextName) {
+ return getInstance(contextName, null);
+ }
+
+ /**
+ * Access a context by name. Contexts are managed as weak references in this class. If no
+ * such valid context exists, a new instance is created, using the given {@code validSupplier}.
+ * @param contextName the context name, not null.
+ * @return the context instance, never null.
+ */
+ public static MetaContext getInstance(String contextName, Supplier<Boolean> validSupplier){
+ synchronized(CONTEXTS){
+ MetaContext ctx = CONTEXTS.get(contextName);
+ if(ctx!=null && ctx.isValid()){
+ return ctx;
+ }
+ ctx = new MetaContext();
+ ctx.id = Objects.requireNonNull(contextName);
+ ctx.validSupplier = validSupplier;
+ CONTEXTS.put(contextName, ctx);
+ return ctx;
+ }
+
+ }
+
+ /**
+ * Access the thread-based context. If no such context
+ * exists a new one will be created.
+ * @return the corresponding context, never null.
+ */
+ public static MetaContext getThreadInstance(){
+ return THREAD_CONTEXT.get();
+ }
+
+ /**
+ * Access the current context, which actually is the current context, combined with the thread based
+ * context (overriding).
+ * @return the corresponding context, never null.
+ */
+ public MetaContext getCurrentInstance(){
+ return this.combineWith(THREAD_CONTEXT.get());
+ }
+
+ /**
+ * Method to evaluate if a context is valid. This basically depends on the
+ * {@code validSupplier}, if any is set. If no supplier is present the context is valid.
+ *
+ * @return true, if this context is valid.
+ */
+ public boolean isValid(){
+ return this.validSupplier == null || validSupplier.get();
+ }
+
+
+ /**
+ * Combine this context with the other contexts given, hereby only contexts are included
+ * which are {@code valid}, see {@link #isValid()}.
+ * @param contexts the context to merge with this context.
+ * @return the newly created Context.
+ */
+ public MetaContext combineWith(MetaContext... contexts) {
+ MetaContext newContext = new MetaContext();
+ newContext.properties.putAll(this.properties);
+ for(MetaContext ctx:contexts) {
+ if(ctx.isValid()) {
+ newContext.properties.putAll(ctx.properties);
+ }
+ }
+ return newContext;
+ }
+
+ /**
+ * Access the given context property.
+ * @param key the key, not null
+ * @return the value, or null.
+ */
+ public String getProperty(String key){
+ return getProperty(key, null);
+ }
+
+ /**
+ * Access the given context property.
+ * @param key the key, not the default value.
+ * @param defaultValue the default value to be returned, if no value is defined, or the
+ * stored value's TTL has been reached.
+ * @return the value, default value 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;
+ }
+
+ /**
+ * Sets the given context property.
+ * @param key the key, not null.
+ * @param value the value, not null.
+ * @return the porevious value, or null.
+ */
+ public String setProperty(String key, String value){
+ return setProperty(key, value, 0, TimeUnit.MILLISECONDS);
+ }
+
+ /**
+ * Sets the given context property.
+ * @param key the key, not null.
+ * @param value the value, not null.
+ * @param ttl the time to live. Zero or less than zero means, no timeout.
+ * @param unit the target time unit.
+ * @return the porevious value, 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;
+ }
+
+ /**
+ * Sets the given property unless there is already a value defined.
+ * @param key the key, not null.
+ * @param value the value, not null.
+ */
+ public void setPropertyIfAbsent(String key, String value){
+ setPropertyIfAbsent(key, value, 0, TimeUnit.MILLISECONDS);
+ }
+
+ /**
+ * Sets the given property unless there is already a value defined.
+ * @param key the key, not null.
+ * @param value the value, not null.
+ * @param ttl the time to live. Zero or less than zero means, no timeout.
+ * @param unit the target time unit.
+ */
+ 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)));
+ }
+ }
+
+ /**
+ * 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.
+ */
+ public void setProperties(Map<String,String> properties, long ttl, TimeUnit unit){
+ for(Map.Entry en:properties.entrySet()) {
+ this.properties.put(
+ en.getKey().toString(),
+ new Value(en.getKey().toString(), en.getValue().toString(), unit.toMillis(ttl)));
+ }
+ }
+
+ /**
+ * 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){
+ for(String key:keys) {
+ if (getProperty(key, null) == null) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * 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);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof MetaContext)) return false;
+
+ MetaContext context = (MetaContext) o;
+
+ return getProperties().equals(context.getProperties());
+
+ }
+
+ @Override
+ public int hashCode() {
+ return getProperties().hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "Context{" +
+ properties +
+ '}';
+ }
+
+ private static final class Value{
+ String key;
+ String value;
+ 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 value is still valid. */
+ boolean isValid(){
+ return this.validUntil<=0 || this.validUntil>=System.currentTimeMillis();
+ }
+
+ /** Method that invalidates a value. */
+ 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, value.value);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(value);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/Refreshable.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/Refreshable.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/Refreshable.java
new file mode 100644
index 0000000..dc51554
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/Refreshable.java
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+/**
+ * Common interface for refreshable items.
+ */
+public interface Refreshable {
+
+ /**
+ * Refreshes the given instance.
+ */
+ void refresh();
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/RefreshablePropertySource.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/RefreshablePropertySource.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/RefreshablePropertySource.java
new file mode 100644
index 0000000..23ca932
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/RefreshablePropertySource.java
@@ -0,0 +1,150 @@
+/*
+ * 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.metamodel.internal.ComponentConfigurator;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+/**
+ * Wrapped property source that allows refreshing/reloading a property source. Hereby a property source must
+ * either
+ * <ul>
+ * <li>have a public parameterless constructor, used for reloading a new instance.</li>
+ * <li>implement itself {@link Refreshable}.</li>
+ * </ul>
+ */
+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);
+ }
+
+ /**
+ * 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) {
+ if(propertySource instanceof RefreshablePropertySource){
+ return (RefreshablePropertySource)propertySource;
+ }
+ return new RefreshablePropertySource(metaConfig, 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.
+ */
+ private void checkRefresh(){
+ long next = nextRefresh.get();
+ if(next > 0 && next<System.currentTimeMillis()){
+ nextRefresh.set(next + refreshPeriod.get());
+ refresh();
+ }
+ }
+
+ /**
+ * Set the refresh period. This will be immedately applied from now. No explicit
+ * refresh will be triggered now.
+ * @param units
+ * @param timeUnit
+ */
+ public void setRefreshPeriod(long units, TimeUnit timeUnit){
+ this.refreshPeriod.set(timeUnit.toMillis(units));
+ this.nextRefresh.set(System.currentTimeMillis() + this.refreshPeriod.get());
+ }
+
+
+ @Override
+ public void refresh() {
+ try {
+ if(this.wrapped instanceof Refreshable){
+ ((Refreshable) this.wrapped).refresh();
+ }else {
+ this.wrapped = this.wrapped.getClass().newInstance();
+ ComponentConfigurator.configure(this.wrapped, metaConfig);
+ }
+ } catch (Exception e) {
+ LOG.log(Level.WARNING, "Failed to reload/refresh PropertySource: " +
+ wrapped.getClass().getName(), e);
+ }
+ }
+
+ @Override
+ public int getOrdinal() {
+ return this.wrapped.getOrdinal();
+ }
+
+ @Override
+ public String getName() {
+ return this.wrapped.getName();
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ return this.wrapped.get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return this.wrapped.getProperties();
+ }
+
+ @Override
+ public boolean isScannable() {
+ return this.wrapped.isScannable();
+ }
+
+ @Override
+ public String toString() {
+ return "RefreshablePropertySource{" +
+ "\n metaConfig=" + metaConfig +
+ "\n wrapped=" + wrapped +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/RefreshablePropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/RefreshablePropertySourceProvider.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/RefreshablePropertySourceProvider.java
new file mode 100644
index 0000000..e71ca56
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/RefreshablePropertySourceProvider.java
@@ -0,0 +1,106 @@
+/*
+ * 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.metamodel.internal.ComponentConfigurator;
+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;
+
+/**
+ * Wrapped property source provider that allows refreshing/reloading a property source provider. Hereby a provider must
+ * either
+ * <ul>
+ * <li>have a public parameterless constructor, used for reloading a new instance.</li>
+ * <li>implement itself {@link Refreshable}.</li>
+ * </ul>
+ */
+public final class RefreshablePropertySourceProvider
+ implements PropertySourceProvider, Refreshable {
+
+ private static final Logger LOG = Logger.getLogger(RefreshablePropertySourceProvider.class.getName());
+ private Map<String,String> metaConfig;
+ private PropertySourceProvider wrapped;
+ private Collection<PropertySource> propertSources;
+
+ private RefreshablePropertySourceProvider(Map<String,String> metaConfig, PropertySourceProvider wrapped) {
+ this.metaConfig = Objects.requireNonNull(metaConfig);
+ this.wrapped = Objects.requireNonNull(wrapped);
+ this.propertSources = Objects.requireNonNull(wrapped.getPropertySources());
+ }
+
+ /**
+ * 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 provider the property source provider, not null.
+ * @return a new instance, not null.
+ */
+ public static RefreshablePropertySourceProvider of(Map<String,String> metaConfig, PropertySourceProvider provider) {
+ if(provider instanceof RefreshablePropertySourceProvider){
+ return (RefreshablePropertySourceProvider)provider;
+ }
+ return new RefreshablePropertySourceProvider(metaConfig, provider);
+ }
+
+ /**
+ * Makes a property source refreshable. If the given property source is already an instance of
+ * RefreshablePropertySource, the property source is returned.
+ * @param provider the property source provider, not null.
+ * @return a new instance, not null.
+ */
+ public static RefreshablePropertySourceProvider of(PropertySourceProvider provider) {
+ return of(Collections.<String, String>emptyMap(), provider);
+ }
+
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ return this.propertSources;
+ }
+
+ @Override
+ public void refresh() {
+ try {
+ if(this.wrapped instanceof Refreshable){
+ ((Refreshable) this.wrapped).refresh();
+ }else {
+ this.wrapped = this.wrapped.getClass().newInstance();
+ ComponentConfigurator.configure(this.wrapped, metaConfig);
+ }
+ } catch (Exception e) {
+ LOG.log(Level.WARNING, "Failed to refresh PropertySourceProvider: " +
+ wrapped.getClass().getName(), e);
+ }
+ this.propertSources = Objects.requireNonNull(wrapped.getPropertySources());
+ }
+
+ @Override
+ public String toString() {
+ return "RefreshablePropertySourceProvider{" +
+ "\n metaConfig=" + metaConfig +
+ "\n wrapped=" + wrapped +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/MetaConfiguration.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/MetaConfiguration.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/MetaConfiguration.java
deleted file mode 100644
index 2e88c6b..0000000
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/MetaConfiguration.java
+++ /dev/null
@@ -1,122 +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.dsl;
-//
-//import org.apache.tamaya.Configuration;
-//import org.apache.tamaya.ConfigurationProvider;
-//import org.apache.tamaya.format.ConfigurationData;
-//import org.apache.tamaya.format.ConfigurationFormat;
-//import org.apache.tamaya.format.ConfigurationFormats;
-//import org.apache.tamaya.json.YAMLFormat;
-//import org.apache.tamaya.resource.ConfigResources;
-//import org.apache.tamaya.spi.ConfigurationContextBuilder;
-//
-//import java.io.InputStream;
-//import java.net.URL;
-//import java.util.ArrayList;
-//import java.util.Arrays;
-//import java.util.List;
-//import java.util.logging.Level;
-//import java.util.logging.Logger;
-//
-///**
-// * Meta environment configuration builder and accessor. Normally this class shoulds never be accessed
-// * by client code. But it could be useful for extensions that extend the meta-configuration capabilities
-// * of tamaya having access to the meta-configuration, so they can read their own meta-entries to
-// * setup whatever features they implement.
-// */
-//public final class MetaConfiguration {
-//
-// private static final Logger LOGGER = Logger.getLogger(MetaConfiguration.class.getName());
-// private static MetaConfiguration INSTANCE = new MetaConfiguration();
-//
-// private Configuration config;
-// private String resourceExpression;
-// private String[] formatNames;
-//
-// /**
-// * Initializes the metaconfiguration.
-// * @param resourceExpression the resource expression that defines the resources to load.
-// * @param formatNames the format names to be used.
-// */
-// private void init(String resourceExpression, String... formatNames){
-// if(this.config!=null){
-// LOGGER.warning(">>> Reset of Meta-Configuration resource : " + resourceExpression);
-// LOGGER.warning(">>> Reset of Meta-Configuration formats : " + Arrays.toString(formatNames));
-// }
-// if(resourceExpression==null){
-// resourceExpression = "tamaya-config.*";
-// }
-// LOGGER.info(">>> Meta-Configuration resource : " + resourceExpression);
-// ConfigurationFormat[] formats = loadFormats(formatNames);
-// ConfigurationContextBuilder builder = ConfigurationProvider.getConfigurationContextBuilder();
-// for(URL url:ConfigResources.getResourceResolver().getResources(resourceExpression)) {
-// for(ConfigurationFormat format:formats) {
-// if(format.accepts(url)){
-// try(InputStream is = url.openStream()){
-// ConfigurationData data = format.readConfiguration(url.toString(), is);
-// builder.addPropertySources(PropertySourceBuilder(
-// url.toString(), data.getCombinedProperties()));
-// }catch(Exception e){
-// LOGGER.log(Level.INFO, "Failed to read " + url + " with format " + format, e);
-// }
-// }
-// }
-// }
-// this.config = ConfigurationProvider.createConfiguration(builder.build());
-// LOGGER.info("Meta-Configuration read: " + this.config.getProperties().size() + " entries.");
-// }
-//
-//
-// /**
-// * Access the system's meta-configuration, initialize if necessary. Normally this class shoulds never be accessed
-// * by client code. But it could be useful for extensions that extend the meta-configuration capabilities
-// * of tamaya having access to the meta-configuration, so they can read their own meta-entries to
-// * setup whatever features they implement.
-// * @return the meta-configuration instance used for setting up the Tamaya's application configuration
-// * model.
-// */
-// public static Configuration getConfiguration(){
-// if(INSTANCE.config==null) {
-// INSTANCE.init(null);
-// }
-// return INSTANCE.config;
-// }
-//
-// /**
-// * Access the system's meta-configuration, initialize if necessary. Normally this class shoulds never be accessed
-// * by client code. But it could be useful for extensions that extend the meta-configuration capabilities
-// * of tamaya having access to the meta-configuration, so they can read their own meta-entries to
-// * setup whatever features they implement.
-// *
-// * @param resourceExpression the resource expression that defines where the metaconfiguration
-// * files/resources are located.
-// * @param formatNames the formats supported, if null all formats found are tried for each resource(=URL).
-// * @return the meta-configuration instance used for setting up the Tamaya's application configuration
-// * model.
-// */
-// public static Configuration getConfiguration(String resourceExpression,
-// String... formatNames){
-// if(INSTANCE.config==null) {
-// INSTANCE.init(resourceExpression, formatNames);
-// }
-// return INSTANCE.config;
-// }
-//
-//}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/TamayaConfigurator.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/TamayaConfigurator.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/TamayaConfigurator.java
deleted file mode 100644
index c4570d7..0000000
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/TamayaConfigurator.java
+++ /dev/null
@@ -1,234 +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.dsl;
-//
-//import org.apache.tamaya.Configuration;
-//import org.apache.tamaya.ConfigurationProvider;
-//import org.apache.tamaya.functions.ConfigurationFunctions;
-//import org.apache.tamaya.spi.*;
-//import org.apache.tamaya.metamodel.spi.DSLPropertySourceProvider;
-//
-//import java.util.ArrayList;
-//import java.util.Collection;
-//import java.util.Collections;
-//import java.util.Comparator;
-//import java.util.HashMap;
-//import java.util.HashSet;
-//import java.util.List;
-//import java.util.Map;
-//import java.util.Set;
-//import java.util.logging.Logger;
-//
-///**
-// * Configuration class setting up the Tamaya runtime model.
-// */
-//public final class TamayaConfigurator {
-//
-// private static final Logger LOGGER = Logger.getLogger(MetaConfiguration.class.getName());
-// private static final Comparator<WrappedPropertySource> ORDINAL_COMPARATOR =
-// new Comparator<WrappedPropertySource>(){
-// @Override
-// public int compare(WrappedPropertySource o1, WrappedPropertySource o2) {
-// return o1.getOrdinal() - o2.getOrdinal();
-// }
-// };
-//
-// private static final TamayaConfigurator INSTANCE = new TamayaConfigurator();
-//
-// private ConfigurationContext configurationContext;
-// private Set<String> formats = new HashSet<>();
-// private Set<String> suffixes = new HashSet<>();
-// private Map<String,DSLPropertySourceProvider> dslResolvers = new HashMap<>();
-//
-//
-// private TamayaConfigurator(){
-// configure(null);
-// }
-//
-// /**
-// * Get the singleton instance.
-// * @return the instance, never null.
-// */
-// public static TamayaConfigurator getInstance(){
-// return INSTANCE;
-// }
-//
-// /**
-// * Configures the Tamaya runtime using the metamodel configuration found at the default
-// * location.
-// * @see MetaConfiguration
-// */
-// public void configure(){
-// configure(null);
-// }
-//
-// /**
-// * Configures the Tamaya runtime using the given resource location expression and (optionally)
-// * formats to be used for evaluating the metamodel configuration.
-// * @param resourceExpression resource expression for resolving the location of the
-// * meta configuration.
-// * @param formats the format names to be used, optional, but not null.
-// * @see MetaConfiguration
-// */
-// public void configure(String resourceExpression, String... formats){
-// loadDSLSourceResolvers();
-// Configuration metaConfig = MetaConfiguration.getConfiguration(resourceExpression, formats);
-// Configuration profilesConfig = metaConfig.with(
-// ConfigurationFunctions.section("TAMAYA.PROFILES.", true));
-// Configuration metaProfile = profilesConfig.with(
-// ConfigurationFunctions.section("<COMMON>.", true));
-// System.out.println(metaProfile.getProperties().keySet());
-// String[] values = metaProfile.getOrDefault("formats","yaml, properties, xml-properties").split(",");
-// for(String fmt:values){
-// fmt = fmt.trim();
-// if(fmt.isEmpty()){
-// continue;
-// }
-// this.formats.add(fmt);
-// }
-// values = metaProfile.getOrDefault("suffixes", "yml, yaml, properties, xml").split(",");
-// for(String sfx:values){
-// sfx = sfx.trim();
-// if(sfx.isEmpty()){
-// continue;
-// }
-// this.suffixes.add(sfx);
-// }
-// ConfigurationContextBuilder builder = ConfigurationProvider.getConfigurationContextBuilder();
-// Map<String, PropertySource> loadedPropertySources = loadDefaultPropertySources();
-// int defaultOrdinal = loadSources(builder, "<COMMON>", metaProfile, loadedPropertySources, 0) + 20;
-// // Load current profiles
-// for(String profile:ProfileManager.getInstance().getActiveProfiles()){
-// metaProfile = profilesConfig.with(
-// ConfigurationFunctions.section(profile, true));
-// defaultOrdinal = loadSources(builder, profile, metaProfile, loadedPropertySources, defaultOrdinal) + 20;
-// }
-// // formats: yaml, properties, xml-properties
-// // - SUFFIX: yaml, yml, properties, xml
-// // - sources:
-// // - "named:env-properties" # provider name, or class name
-// // - "named:main-args"
-// // - "named:sys-properties"
-// // - "resource:classpath:META-INF/config/**/*.SUFFIX"
-//
-// }
-//
-// /**
-// * Loads all default registered property sources and providers.
-// * @return the default property sources available on the system.
-// */
-// private Map<String, PropertySource> loadDefaultPropertySources() {
-// Map<String, PropertySource> loadedPropertySources = new HashMap<>();
-// for(PropertySource ps: ServiceContextManager.getServiceContext().getServices(PropertySource.class)){
-// loadedPropertySources.put(ps.getName(), ps);
-// }
-// for(PropertySourceProvider prov: ServiceContextManager.getServiceContext().getServices(PropertySourceProvider.class)){
-// for(PropertySource ps: prov.getPropertySources()){
-// loadedPropertySources.put(ps.getName(), ps);
-// }
-// }
-// return loadedPropertySources;
-// }
-//
-// private int loadSources(ConfigurationContextBuilder builder, String profileId, Configuration metaProfile, Map<String,
-// PropertySource> defaultPropertySources, int nextOrdinal) {
-// String[] values;
-// List<PropertySource> propertySourcesLoaded = new ArrayList<>();
-// values = metaProfile.getOrDefault("sources","<default>").split(",");
-// if(values.length==1 && "<default>".equals(values[0])){
-// // load default property sources and providers from config as default.
-// // additional providers may be added depending on the active profile...
-// LOGGER.info("Using default configuration setup for "+profileId);
-// nextOrdinal = addAndGetNextOrdinal(builder, defaultPropertySources.values(),
-// propertySourcesLoaded, nextOrdinal);
-// }else {
-// LOGGER.info("Loading DSL based "+profileId+" configuration context...");
-// int count = 0;
-// for (String source : values) {
-// source = source.trim();
-// if (source.isEmpty()) {
-// continue;
-// }
-// String sourceKey = getSourceKey(source);
-// LOGGER.info("Loading "+profileId+" configuration source: " + source);
-// // evaluate DSLSourceResolver and resolve PropertySources, register thm into context
-// // apply newMaxOrdinal...
-// DSLPropertySourceProvider resolver = dslResolvers.get(sourceKey);
-// if(resolver==null){
-// LOGGER.warning("DSL error: unresolvable source expression: "+ source);
-// continue;
-// }
-// List<PropertySource> sources = resolver.resolve(source.substring(sourceKey.length()),
-// defaultPropertySources);
-// nextOrdinal = addAndGetNextOrdinal(builder, sources, propertySourcesLoaded, nextOrdinal);
-// }
-// LOGGER.info("Loaded "+count+" DSL based "+profileId+" configuration contexts.");
-// }
-// return nextOrdinal;
-// }
-//
-// private int addAndGetNextOrdinal(ConfigurationContextBuilder builder, Collection<PropertySource> sourcesToAdd,
-// List<PropertySource> allPropertySources, int nextOrdinal) {
-// allPropertySources.addAll(wrapOrdinals(nextOrdinal, sourcesToAdd));
-// nextOrdinal = Math.max(calculateHighestOrdinal(allPropertySources)+1, nextOrdinal+1);
-// builder.addPropertySources(allPropertySources);
-// return nextOrdinal;
-// }
-//
-// private List<WrappedPropertySource> wrapOrdinals(int nextOrdinal, Collection<PropertySource> propertySources) {
-// List<WrappedPropertySource> result = new ArrayList<>();
-// for(PropertySource ps: propertySources){
-// result.add(WrappedPropertySource.of(ps));
-// }
-// Collections.sort(result, ORDINAL_COMPARATOR);
-// for(WrappedPropertySource ps: result){
-// ps.setOrdinal(nextOrdinal++);
-// }
-// Collections.sort(result, ORDINAL_COMPARATOR);
-// return result;
-// }
-//
-// private int calculateHighestOrdinal(Collection<PropertySource> sources) {
-// int maxOrdinal = 0;
-// for (PropertySource ps : sources) {
-// if (ps.getOrdinal() > maxOrdinal) {
-// maxOrdinal = ps.getOrdinal();
-// }
-// }
-// return maxOrdinal;
-// }
-//
-// private String getSourceKey(String source) {
-// int index = source.indexOf(':');
-// if(index>0){
-// return source.substring(0,index);
-// }
-// return source;
-// }
-//
-// private void loadDSLSourceResolvers() {
-// // Load the ConfigurationDSLSourceResolvers on the system
-// for(DSLPropertySourceProvider res:
-// ServiceContextManager.getServiceContext().getServices(
-// DSLPropertySourceProvider.class)){
-// this.dslResolvers.put(res.getKey(), res);
-// }
-// }
-//
-//}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/WrappedPropertySource.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/WrappedPropertySource.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/WrappedPropertySource.java
deleted file mode 100644
index 000406b..0000000
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/WrappedPropertySource.java
+++ /dev/null
@@ -1,127 +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.dsl;
-
-import org.apache.tamaya.spi.FilterContext;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * Wrapped property source that allows dynamically reassigning the property source's
- * ordinal value. This is needed for reordering the property sources to
- * match the DSL configured ordering.
- */
-final class WrappedPropertySource implements PropertySource {
-
- private Integer ordinalAssigned;
- private PropertySource wrapped;
- private List<PropertyFilter> filters;
-
- private WrappedPropertySource(PropertySource wrapped){
- this.wrapped = Objects.requireNonNull(wrapped);
- }
-
- /**
- * Wraps a given property source.
- * @param propertySource the property source to be wrapped.
- * @return a wrapped property source.
- */
- public static WrappedPropertySource of(PropertySource propertySource){
- if(propertySource instanceof WrappedPropertySource){
- return (WrappedPropertySource)propertySource;
- }
- return new WrappedPropertySource(propertySource);
- }
-
- @Override
- public int getOrdinal() {
- return ordinalAssigned!=null?ordinalAssigned.intValue():wrapped.getOrdinal();
- }
-
- /**
- * Applies the given ordinal to the instance.
- * @param ordinal the new ordinal.
- */
- public void setOrdinal(int ordinal){
- this.ordinalAssigned = ordinal;
- }
-
- /**
- * Resetting the ordinal to the one of the wrapped property source.
- */
- public void resetOrdinal(){
- this.ordinalAssigned = null;
- }
-
- @Override
- public String getName() {
- return wrapped.getName();
- }
-
- @Override
- public PropertyValue get(String key) {
- PropertyValue value = wrapped.get(key);
- if(value != null && value.getValue()!=null){
- if(filters!=null){
- String filteredValue = value.getValue();
- for(PropertyFilter pf:filters){
- filteredValue = pf.filterProperty(filteredValue, new FilterContext(key, value.getConfigEntries(), true));
- }
- if(filteredValue!=null){
- return PropertyValue.builder(key, filteredValue, getName())
- .setContextData(value.getConfigEntries()).build();
- }
- }
- }
- return value;
- }
-
- @Override
- public Map<String, String> getProperties() {
- Map<String, String> props = wrapped.getProperties();
- if(filters!=null){
- String filteredValue = value.getValue();
- for(PropertyFilter pf:filters){
- filteredValue = pf.filterProperty(filteredValue, new FilterContext(key, value.getConfigEntries(), true));
- }
- if(filteredValue!=null){
- return PropertyValue.builder(key, filteredValue, getName())
- .setContextData(value.getConfigEntries()).build();
- }
- }
- }
-
- @Override
- public boolean isScannable() {
- return wrapped.isScannable();
- }
-
- @Override
- public String toString() {
- return "WrappedPropertySource{" +
- "ordinalAssigned=" + ordinalAssigned +
- ", wrapped=" + wrapped +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/internal/DSLLoadingConfigurationProviderSpi.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/internal/DSLLoadingConfigurationProviderSpi.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/internal/DSLLoadingConfigurationProviderSpi.java
deleted file mode 100644
index e640e3f..0000000
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/internal/DSLLoadingConfigurationProviderSpi.java
+++ /dev/null
@@ -1,81 +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.dsl.internal;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.metamodel.dsl.TamayaConfigurator;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.ConfigurationProviderSpi;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import javax.annotation.Priority;
-
-/**
- * ConfigurationContext that uses {@link TamayaConfigurator} to configure the
- * Tamaya runtime context.
- */
-@Priority(10)
-public class DSLLoadingConfigurationProviderSpi implements ConfigurationProviderSpi{
-
- private boolean configured;
-
- private ConfigurationContext context = ConfigurationProvider.getConfigurationContextBuilder().build();
- private Configuration config = ConfigurationProvider.createConfiguration(context);
-
-
- @Override
- public ConfigurationContextBuilder getConfigurationContextBuilder() {
- return ServiceContextManager.getServiceContext().getService(ConfigurationContextBuilder.class);
- }
-
- @Override
- public void setConfigurationContext(ConfigurationContext context){
- // TODO think on a SPI or move event part into API...
- this.config = ConfigurationProvider.createConfiguration(context);
- this.context = context;
- }
-
- @Override
- public boolean isConfigurationContextSettable() {
- return true;
- }
-
- @Override
- public Configuration getConfiguration() {
- checkInitialized();
- return config;
- }
-
- @Override
- public ConfigurationContext getConfigurationContext() {
- checkInitialized();
- return context;
- }
-
- private void checkInitialized() {
- if(!configured){
- synchronized (context) {
- TamayaConfigurator.getInstance().configure();
- configured = true;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/internal/NamedDSLPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/internal/NamedDSLPropertySourceProvider.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/internal/NamedDSLPropertySourceProvider.java
deleted file mode 100644
index 6c50dc1..0000000
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/internal/NamedDSLPropertySourceProvider.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.metamodel.dsl.internal;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.metamodel.spi.DSLPropertySourceProvider;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Logger;
-
-/**
- * DSL provider implementation that allows to use registered {@link PropertySource} instances
- * by matching {@link PropertySource#getName()} with the configured value and overriding the
- * {@link PropertySource#getOrdinal()} method.
- */
-public class NamedDSLPropertySourceProvider implements DSLPropertySourceProvider{
-
- private static final Logger LOG = Logger.getLogger(NamedDSLPropertySourceProvider.class.getName());
-
- @Override
- public List<PropertySource> resolve(String sourceExpression, Map<String, PropertySource> defaultPropertySources) {
- List<PropertySource> result = new ArrayList<>();
- PropertySource ps = defaultPropertySources.get(sourceExpression);
- if(ps==null){
- LOG.warning("No such property source provider found: " + sourceExpression);
- }
- result.add(ps);
- return result;
- }
-
- @Override
- public String getKey() {
- return "named:";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/internal/ResourceDSLPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/internal/ResourceDSLPropertySourceProvider.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/internal/ResourceDSLPropertySourceProvider.java
deleted file mode 100644
index f2f2a71..0000000
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/dsl/internal/ResourceDSLPropertySourceProvider.java
+++ /dev/null
@@ -1,82 +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.dsl.internal;
-
-import org.apache.tamaya.metamodel.dsl.DSLFormatManager;
-import org.apache.tamaya.format.ConfigurationData;
-import org.apache.tamaya.format.ConfigurationFormat;
-import org.apache.tamaya.resource.ConfigResources;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spisupport.MapPropertySource;
-import org.apache.tamaya.metamodel.spi.DSLPropertySourceProvider;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * DSL provider implementation that allows to use registered {@link PropertySource} instances
- * by matching {@link PropertySource#getName()} with the configured value and overriding the
- * {@link PropertySource#getOrdinal()} method.
- */
-public class ResourceDSLPropertySourceProvider implements DSLPropertySourceProvider{
-
- private static final Logger LOG = Logger.getLogger(ResourceDSLPropertySourceProvider.class.getName());
-
- @Override
- public List<PropertySource> resolve(String sourceExpression, Map<String, PropertySource> defaultPropertySources) {
- List<PropertySource> result = new ArrayList<>();
- List<URL> resources = new ArrayList<>();
- if(sourceExpression.contains("SUFFIX")) {
- for (String suffix : DSLFormatManager.getInstance().getSuffixes()) {
- Collection<URL> locations = ConfigResources.getResourceResolver().getResources(getClass().getClassLoader(),
- sourceExpression.replace("SUFFIX", suffix));
- loadPropertySources(locations, result);
- }
- }else {
- Collection<URL> locations = ConfigResources.getResourceResolver().getResources(getClass().getClassLoader(),
- sourceExpression);
- loadPropertySources(locations, result);
- }
- return result;
- }
-
- private void loadPropertySources(Collection<URL> locations, List<PropertySource> result) {
- for(URL url:locations){
- for(ConfigurationFormat format: DSLFormatManager.getInstance().getFormats()) {
- try(InputStream is = url.openStream()){
- ConfigurationData data = format.readConfiguration(url.toString(),is);
- result.add(new MapPropertySource(url.toString(), data.getCombinedProperties()));
- }catch(Exception e){
- LOG.log(Level.FINEST, "Format failed: " + format.getName() + " for " + url, e);
- }
- }
- }
- }
-
- @Override
- public String getKey() {
- return "resource:";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/CombinationPolicyReader.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/CombinationPolicyReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/CombinationPolicyReader.java
new file mode 100644
index 0000000..4c9217d
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/CombinationPolicyReader.java
@@ -0,0 +1,61 @@
+/*
+ * 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.ConfigException;
+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.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.util.logging.Logger;
+
+
+/**
+ * Metaconfiguration reader that reads the configuration combination policy to be used.
+ */
+public class CombinationPolicyReader implements MetaConfigurationReader{
+
+ private static final Logger LOG = Logger.getLogger(CombinationPolicyReader.class.getName());
+
+ @Override
+ public void read(Document document, ConfigurationContextBuilder contextBuilder) {
+ NodeList nodeList = document.getDocumentElement().getElementsByTagName("combination-policy");
+ if(nodeList.getLength()==0){
+ LOG.finest("No explicit combination policy configured, using default.");
+ return;
+ }
+ if(nodeList.getLength()>1){
+ throw new ConfigException("Only one combination policy can be applied.");
+ }
+ Node node = nodeList.item(0);
+ String type = node.getAttributes().getNamedItem("type").getNodeValue();
+ LOG.finest("Loading combination policy configured: " + type);
+ ItemFactory<PropertyValueCombinationPolicy> policyFactory = ItemFactoryManager.getInstance().getFactory(PropertyValueCombinationPolicy.class, type);
+ PropertyValueCombinationPolicy policy = policyFactory.create(ComponentConfigurator.extractParameters(node));
+ ComponentConfigurator.configure(policy, node);
+ contextBuilder.setPropertyValueCombinationPolicy(policy);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..93c50da
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java
@@ -0,0 +1,87 @@
+/*
+ * 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.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.util.*;
+import java.util.logging.Logger;
+
+/**
+ * Small helper class for loading of configured instances.
+ */
+public final class ComponentConfigurator<T> {
+
+ private static final Logger LOG = Logger.getLogger(ComponentConfigurator.class.getName());
+
+ private ComponentConfigurator(){}
+
+ /**
+ * Configures the given instance with whatever is defined in the current child nodes.
+ * @param instance the instance to be configured, not null.
+ * @param node the node containing any configuration child nodes, not null.
+ */
+ public static void configure(Object instance, Node node) {
+ NodeList entryNodes = node.getChildNodes();
+ Map<String,String> params = new HashMap<>();
+ for(int c=0;c<entryNodes.getLength();c++) {
+ Node filterNode = entryNodes.item(c);
+ if ("param".equals(filterNode.getNodeName())) {
+ String key = filterNode.getAttributes().getNamedItem("name").getNodeValue();
+ String value = filterNode.getTextContent();
+ params.put(key, value);
+ }
+ }
+ configure(instance, params);
+ }
+
+ /**
+ * Configures the given instance with whatever is defined in the current child nodes.
+ * @param instance the instance to be configured, not null.
+ * @param params the node containing any configuration child nodes, not null.
+ */
+ public static void configure(Object instance, Map<String,String> params) {
+ LOG.finest("Configuring instance: " + instance + " with " + params);
+ for(Map.Entry<String,String> en:params.entrySet()){
+ if(!params.isEmpty()){
+ applyParam(instance, en.getKey(), en.getValue());
+ }
+ }
+ }
+
+ private static void applyParam(Object instance, String param, String value) {
+ // TODO apply parameters to instance using reflection ,only if found.
+ }
+
+ public static Map<String, String> extractParameters(Node node) {
+ NodeList entryNodes = node.getChildNodes();
+ Map<String,String> params = new HashMap<>();
+ for(int c=0;c<entryNodes.getLength();c++) {
+ Node filterNode = entryNodes.item(c);
+ if ("param".equals(filterNode.getNodeName())) {
+ String key = filterNode.getAttributes().getNamedItem("name").getNodeValue();
+ String value = filterNode.getTextContent();
+ params.put(key, value);
+ }
+ }
+ return params;
+ }
+
+}
[3/5] incubator-tamaya-sandbox git commit: Added tests for OSGI
support,
simplified OSGI support. Implemented base functionality for metamodel support,
including first testing.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/ItemFactoryManager.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..4578640
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/ItemFactoryManager.java
@@ -0,0 +1,145 @@
+/*
+ * 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.spi;
+
+import org.apache.tamaya.spi.PropertySource;
+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;
+
+/**
+ * Created by atsticks on 04.12.16.
+ */
+public final class ItemFactoryManager {
+
+ private static final Logger LOG = Logger.getLogger(ItemFactoryManager.class.getName());
+
+ private Map<Class, List<ItemFactory<?>>> factoryRegistry = new ConcurrentHashMap<>();
+
+ private static ItemFactoryManager INSTANCE = new ItemFactoryManager();
+
+ private ItemFactoryManager(){
+ }
+
+ public static ItemFactoryManager getInstance(){
+ return INSTANCE;
+ }
+
+ public <T> List<ItemFactory<T>> getFactories(Class<T> type){
+ List<ItemFactory<?>> factories = factoryRegistry.get(type);
+ if(factories==null){
+ Collection<ItemFactory> allFactories =
+ ServiceContextManager.getServiceContext().getServices(ItemFactory.class);
+ for(ItemFactory fact:allFactories){
+ registerItemFactory(fact);
+ }
+ }
+ factories = factoryRegistry.get(type);
+ if(factories==null){
+ return Collections.emptyList();
+ }
+ return List.class.cast(factories);
+ }
+
+ public <T> ItemFactory<T> getFactory(Class<T> type, String id) {
+ List<ItemFactory<T>> factories = getFactories(type);
+ for(ItemFactory<T> f:factories){
+ if(id.equals(f.getName())){
+ return f;
+ }
+ }
+ // try creating a new factory with the given id as fully qualified class name...
+ try{
+ Class<? extends ItemFactory> instanceType = (Class<? extends ItemFactory>) Class.forName(id);
+ ItemFactory<T> factory = new SimpleItemFactory(type, instanceType);
+ registerItemFactory(factory);
+ return factory;
+ }catch(Exception e){
+ LOG.severe("Failed to create factory for configured class: " + type.getName() +
+ " and type: " + id);
+ return null;
+ }
+ }
+
+ public <T> void registerItemFactory(ItemFactory<T> factory) {
+ List<ItemFactory<?>> factories = factoryRegistry.get(factory.getType());
+ if(factories==null){
+ factories = new ArrayList<>();
+ factoryRegistry.put(factory.getType(), factories);
+ }
+ factories.add(factory);
+ }
+
+ private static class SimpleItemFactory<I> implements ItemFactory<I> {
+
+ private Class<I> type;
+ private Class<? extends I> instanceType;
+
+ public SimpleItemFactory(Class<I> type, Class<? extends I> instanceType) {
+ this.type = Objects.requireNonNull(type);
+ this.instanceType = Objects.requireNonNull(instanceType);
+ }
+
+ @Override
+ public String getName() {
+ return getType().getName();
+ }
+
+ @Override
+ public I create(Map<String, String> parameters) {
+ try {
+ return instanceType.newInstance();
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Failed to create configured instance of type:" + instanceType, e);
+ return null;
+ }
+ }
+
+ @Override
+ public Class<I> getType() {
+ return type;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof SimpleItemFactory)) return false;
+ SimpleItemFactory<?> that = (SimpleItemFactory<?>) o;
+ return Objects.equals(getType(), that.getType()) &&
+ Objects.equals(instanceType, that.instanceType);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getType(), instanceType);
+ }
+
+ @Override
+ public String toString() {
+ return "SimpleItemFactory{" +
+ "type=" + type +
+ ", instanceType=" + instanceType +
+ '}';
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/MetaConfigurationReader.java
----------------------------------------------------------------------
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 c9718a9..005aa24 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,14 +18,12 @@
*/
package org.apache.tamaya.metamodel.spi;
-import org.apache.tamaya.metamodel.Context;
import org.apache.tamaya.spi.ConfigurationContextBuilder;
import org.w3c.dom.Document;
-import java.net.URL;
-
/**
- * Created by atsticks on 03.11.16.
+ * Reader that reads meta configuration from the meta configuration XML source.
+ * This SPI allows to allow different aspects to be configured by different modules.
*/
public interface MetaConfigurationReader {
@@ -36,6 +34,6 @@ public interface MetaConfigurationReader {
* @param document the meta-configuration document
* @param contextBuilder the context builder to use.
*/
- void read(Document document, Context context, ConfigurationContextBuilder contextBuilder);
+ void read(Document document, ConfigurationContextBuilder contextBuilder);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/PropertySourceFactory.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/PropertySourceFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/PropertySourceFactory.java
deleted file mode 100644
index 7da2e58..0000000
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/PropertySourceFactory.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.metamodel.spi;
-
-import org.apache.tamaya.metamodel.internal.SourceConfig;
-import org.apache.tamaya.spi.PropertySource;
-
-import java.util.Map;
-
-
-/**
- * {@link PropertySource} and {@link SourceConfig} instances that
- * implement configurable are configured with the according configuration
- * settings provided in the {@code tamaya-config.xml} meta-configuration.
- */
-public interface PropertySourceFactory {
-
- /**
- * Resolve the given expression (without the key part).
- * @param config any further extended configuration, not null, but may be
- * empty.
- * @return the property source, or null.
- */
- PropertySource create(Map<String, String> config);
-
- /**
- * Get the property source type. The type is used to identify the correct factory instance
- * to resolve a configured property source.
- * @return the (unique) type key, never null and not empty.
- */
- String getType();
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/PropertySourceProviderFactory.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/PropertySourceProviderFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/PropertySourceProviderFactory.java
deleted file mode 100644
index 41ea3a5..0000000
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/PropertySourceProviderFactory.java
+++ /dev/null
@@ -1,49 +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.spi;
-
-import org.apache.tamaya.metamodel.internal.SourceConfig;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-
-import java.util.Map;
-
-
-/**
- * {@link PropertySource} and {@link SourceConfig} instances that
- * implement configurable are configured with the according configuration
- * settings provided in the {@code tamaya-config.xml} meta-configuration.
- */
-public interface PropertySourceProviderFactory {
-
- /**
- * Resolve the given expression (without the key part).
- * @param config any further extended configuration, not null, but may be
- * empty.
- * @return the property source, or null.
- */
- PropertySourceProvider create(Map<String, String> config);
-
- /**
- * Get the property source type. The type is used to identify the correct factory instance
- * to resolve a configured property source.
- * @return the (unique) type key, never null and not empty.
- */
- String getType();
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.DSLPropertySourceProvider
----------------------------------------------------------------------
diff --git a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.DSLPropertySourceProvider b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.DSLPropertySourceProvider
deleted file mode 100644
index f2b1843..0000000
--- a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.DSLPropertySourceProvider
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.metamodel.dsl.internal.NamedDSLPropertySourceProvider
-org.apache.tamaya.metamodel.dsl.internal.ResourceDSLPropertySourceProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ItemFactory
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..7b73763
--- /dev/null
+++ b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ItemFactory
@@ -0,0 +1,26 @@
+#
+# 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.
+#
+org.apache.tamaya.metamodel.internal.factories.CLIArgumentsFactory
+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.URLPropertySourceFactory
+
+org.apache.tamaya.metamodel.internal.factories.ResourcePropertySourceProviderFactory
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..cd2af30
--- /dev/null
+++ b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader
@@ -0,0 +1,26 @@
+#
+# 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.
+#
+
+org.apache.tamaya.metamodel.internal.PropertyFilterReader
+org.apache.tamaya.metamodel.internal.PropertyConverterReader
+org.apache.tamaya.metamodel.internal.PropertySourceReader
+org.apache.tamaya.metamodel.internal.ContextReader
+org.apache.tamaya.metamodel.internal.CombinationPolicyReader
+org.apache.tamaya.metamodel.internal.PropertyFilterOrderingReader
+org.apache.tamaya.metamodel.internal.PropertySourceOrderingReader
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
index 6406156..f9a7797 100644
--- a/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
+++ b/metamodel/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
@@ -16,4 +16,5 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.metamodel.dsl.internal.DSLLoadingConfigurationProviderSpi
\ No newline at end of file
+
+org.apache.tamaya.metamodel.internal.DSLLoadingConfigurationProviderSpi
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/test/resources/IntegrationTests/empty-config.xml
----------------------------------------------------------------------
diff --git a/metamodel/src/test/resources/IntegrationTests/empty-config.xml b/metamodel/src/test/resources/IntegrationTests/empty-config.xml
new file mode 100644
index 0000000..42faaed
--- /dev/null
+++ b/metamodel/src/test/resources/IntegrationTests/empty-config.xml
@@ -0,0 +1,24 @@
+<!--
+// 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>
+
+ <!-- This is an empty config, which results in an empty and unusable configuration. -->
+
+</configuration>
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/test/resources/tamaya-config.xml
----------------------------------------------------------------------
diff --git a/metamodel/src/test/resources/tamaya-config.xml b/metamodel/src/test/resources/tamaya-config.xml
index 1d25beb..eb44f83 100644
--- a/metamodel/src/test/resources/tamaya-config.xml
+++ b/metamodel/src/test/resources/tamaya-config.xml
@@ -20,44 +20,68 @@
<!-- Context is evaluated first. -->
<context>
<context-entry name="stage">${properties:system:STAGE?default=DEV}</context-entry>
+ <context-entry name="configdir">${properties:system:configdir?default=.}</context-entry>
<context-entry name="app">${properties:system.APP?default=NONE}</context-entry>
<context-entry name="context">${java:org.apache.tamaya.context.Context#id()}</context-entry>
<context-entry name="company">Trivadis</context-entry>
<context-entry name="default-formats">yaml,json</context-entry>
+ <context-entry name="default-refresh-period">5 SECOND</context-entry>
</context>
+ <context name="APP">
+ <context-entry name="application">someAppName</context-entry>
+ </context>
+
+ <!-- combinationPolicy type="" / -->
<!-- Configuration definition. -->
- <config-sources>
+ <property-sources>
<source enabled="${stage=TEST || stage=PTA || stage=PROD}"
- uri="properties:environment">
- <filter type="mapping">ENV.</filter>
- <filter type="access-control">
+ type="env-properties">
+ <filter type="PropertyMapping">
+ <param name="mapTarget">ENV.</param>
+ </filter>
+ <filter type="AccessMask">
<param name="roles">admin,power-user</param>
<param name="policy">mask</param>
+ <param name="mask">*****</param>
+ <param name="matchExpression">SEC_</param>
</filter>
</source>
- <source uri="properties:system"/>
- <source name="FILE:config.json" refresh-period="5000"
- uri="file:/./config.json" >
- <param name="observe-period">20000</param>
- <param name="formats">json</param>
+ <source type="sys-properties" >
+ <filter type="ImmutablePropertySource" />
</source>
- <source-provider name="classpath:application-config.yml" uri="classpath*://META-INF/application-config.yml">
- <param name="formats">yaml</param>
- </source-provider>
- <source name="MINE" uri="class:ch.mypack.MyClassSource">
- <param name="locale">de</param>
+ <source type="file" refreshable="true">
+ <name>config.json</name>
+ <param name="location">config.json</param>
+ </source>
+ <source type="file" refreshable="true">
+ <name>config.xml</name>
+ <param name="location">config.xml</param>
+ <param name="formats">xml-properties</param>
</source>
- <include enabled="${stage==TEST}">TEST-config.xml</include>
- <source-provider name="CONFIG-DIR" uri="resource:/${CONFIG-DIR}/**/*.json"/>
- <source name="SERVER" uri="https://www.confdrive.com/cfg/customerId=${}">
- <param name="locale">de</param>
+ <source-provider type="resource">
+ <name>classpath:application-config.yml</name>
+ <param name="location">/META-INF/application-config.yml</param>
+ </source-provider>
+ <source type="ch.mypack.MyClassSource" />
+ <!--<include enabled="${stage==TEST}">TEST-config.xml</include>-->
+ <source-provider type="resource" enabled="${configdir != null}">
+ <name>config-dir</name>
+ <param name="location">/${configdir}/**/*.json</param>
+ </source-provider>
+ <source type="url" refreshable="true">
+ <name>remote</name>
+ <param name="location">https://www.confdrive.com/cfg/customerId=1234</param>
+ <param name="formats">json</param>
+ <filter type="CachedPropertySource">
+ <param name="ttl">30 SECOND</param>
+ </filter>
</source>
- </config-sources>
- <config-filters>
+ </property-sources>
+ <property-filters>
<filter type="UsageTrackerFilter"/>
- <filter type="access-control">
+ <filter type="AccessControl">
<param name="roles">admin,power-user</param>
<param name="policy">hide</param>
<param name="expression">*.secret</param>
@@ -66,10 +90,11 @@
<param name="ttl">30000</param>
<param name="expression">cached.*</param>
</filter>
- </config-filters>
- <!--<converters>-->
+ </property-filters>
+ <property-converters>
<!--<converter type="AllInOneConverter"/>-->
- <!--</converters>-->
+ <default-converters/>
+ </property-converters>
</configuration>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 63240ed..9d5b629 100644
--- a/pom.xml
+++ b/pom.xml
@@ -249,6 +249,71 @@ under the License.
</dependency>
<dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-bom</artifactId>
+ <version>${arquillian.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-container-managed</artifactId>
+ <version>${arquillian.deamon.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-container-common</artifactId>
+ <version>${arquillian.deamon.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-main</artifactId>
+ <version>${arquillian.deamon.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-protocol-arquillian</artifactId>
+ <version>${arquillian.deamon.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-protocol-wire</artifactId>
+ <version>${arquillian.deamon.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-server</artifactId>
+ <version>${arquillian.deamon.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>${mockito.version}</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </exclusion>
+ </exclusions>
+
+ </dependency>
+
+ <dependency>
<groupId>rubygems</groupId>
<artifactId>asciidoctor-diagram</artifactId>
<version>${asciidoctor-diagramm.version}</version>
@@ -260,24 +325,420 @@ under the License.
<artifactId>geronimo-json_1.0_spec</artifactId>
<version>${json.spec.version}</version>
</dependency>
+
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<version>${johnzon.version}</version>
</dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-library</artifactId>
- <version>${hamcrest.version}</version>
- <scope>test</scope>
- </dependency>
+
</dependencies>
</dependencyManagement>
<build>
<defaultGoal>clean install</defaultGoal>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>0.7.7.201606060606</version>
+ </plugin>
+ <plugin>
+ <groupId>de.saumya.mojo</groupId>
+ <artifactId>gem-maven-plugin</artifactId>
+ <version>${gem.plugin}</version>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${checkstyle.version}</version>
+ <executions>
+ <execution>
+ <id>verify-style</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <logViolationsToConsole>true</logViolationsToConsole>
+ <configLocation>checkstyle/style.xml</configLocation>
+ </configuration>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>buildconfigurations</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.puppycrawl.tools</groupId>
+ <artifactId>checkstyle</artifactId>
+ <version>6.2</version>
+ <exclusions><!-- MCHECKSTYLE-156 -->
+ <exclusion>
+ <groupId>com.sun</groupId>
+ <artifactId>tools</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <version>${sources.plugin}</version>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-toolchains-plugin</artifactId>
+ <version>${toolchains.plugin}</version>
+ </plugin>
+<!--
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>${findbugs.version}</version>
+
+ <executions>
+ <execution>
+ <id>findbugs-analyze</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <effort>Max</effort>
+ <threshold>Low</threshold>
+ <failOnError>true</failOnError>
+ <excludeFilterFile>findbugs/findbugs-exclude.xml</excludeFilterFile>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>buildconfigurations</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+-->
+ <plugin>
+ <groupId>org.asciidoctor</groupId>
+ <artifactId>asciidoctor-maven-plugin</artifactId>
+ <version>${asciidoctor.version}</version>
+ <dependencies>
+ <dependency>
+ <!-- See TAMAYA-10 for details on this dependency -->
+ <groupId>org.asciidoctor</groupId>
+ <artifactId>asciidoctorj</artifactId>
+ <version>${asciidoctorj.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.5.1</version>
+ <configuration>
+ <debug>true</debug>
+ <optimize>${maven.compile.optimize}</optimize>
+ <source>${maven.compile.sourceLevel}</source>
+ <target>${maven.compile.targetLevel}</target>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ <showDeprecation>${maven.compile.deprecation}</showDeprecation>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <inherited>true</inherited>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ <configuration>
+ <argLine>-Xms512m -Xmx1048m -XX:MaxPermSize=512m</argLine>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <inherited>true</inherited>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <addMavenDescriptor>false</addMavenDescriptor>
+ <manifestEntries>
+ <Specification-Title>Apache ${project.name}</Specification-Title>
+ <Specification-Version>${project.version}</Specification-Version>
+ <Specification-Vendor>The Apache Software Foundation</Specification-Vendor>
+ <Implementation-Title>${project.name}</Implementation-Title>
+ <Implementation-Version>${project.version} ${buildNumber}</Implementation-Version>
+ <Implementation-Vendor>The Apache Software Foundation</Implementation-Vendor>
+ <SCM-Revision>${buildNumber}</SCM-Revision>
+ <SCM-url>${project.scm.url}</SCM-url>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>bnd-maven-plugin</artifactId>
+ <version>3.3.0</version>
+ <dependencies>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>1.1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.13</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <goals>
+ <goal>bnd-process</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-scm-publish-plugin</artifactId>
+ <version>1.1</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-site-plugin</artifactId>
+ <!-- 20160816: 3.5.1 generates a broken site, maybe due to old asciidoc version?! -->
+ <version>3.4</version>
+ <inherited>true</inherited>
+ <dependencies>
+ <!-- 3.5.1: Fixes class not found
+ executing org.apache.maven.plugins:maven-site-plugin:3.5.1:site: org/apache/maven/doxia/sink/impl/XhtmlBaseSink
+ <dependency>
+ <groupId>org.apache.maven.doxia</groupId>
+ <artifactId>doxia-core</artifactId>
+ <version>1.7</version>
+ </dependency>
+ -->
+ <dependency><!-- add support for ssh/scp -->
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-ssh</artifactId>
+ <version>2.10</version>
+ </dependency>
+ <dependency>
+ <groupId>org.asciidoctor</groupId>
+ <artifactId>asciidoctor-maven-plugin</artifactId>
+ <version>${asciidoctor.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>lt.velykis.maven.skins</groupId>
+ <artifactId>reflow-velocity-tools</artifactId>
+ <version>${reflow-skin.version}</version>
+ </dependency>
+ <!-- Reflow skin requires Velocity >= 1.7 -->
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity</artifactId>
+ <version>1.7</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <version>2.5.3</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <version>${rat.version}</version>
+ <configuration>
+ <excludes>
+ <exclude>**/*banner.txt</exclude>
+ <exclude>banner.txt</exclude>
+ <exclude>.git</exclude>
+ <exclude>derby.log</exclude>
+ <exclude>**/bootstrap-*</exclude>
+ <exclude>**/js/jquery-*</exclude>
+ <!-- json can't get comments -->
+ <exclude>**/*.json</exclude>
+ <exclude>**/*.md</exclude>
+ <exclude>**/*.md.vm</exclude>
+ <exclude>src/site/asciidoc/temp-properties-files-for-site/attributes.adoc</exclude>
+ <exclude>readme/**</exclude>
+ </excludes>
+ <includes>
+ <include>src/**/*</include>
+ <include>pom.xml</include>
+ </includes>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>validate</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+
<plugins>
<plugin>
+ <groupId>org.apache.karaf.tooling</groupId>
+ <artifactId>karaf-maven-plugin</artifactId>
+ <version>4.0.5</version>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>generate</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>features-generate-descriptor</goal>
+ </goals>
+ <configuration>
+ <startLevel>80</startLevel>
+ <aggregateFeatures>true</aggregateFeatures>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>bal</id>
+ <phase>pre-site</phase>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <inherited>false</inherited>
+ <configuration>
+ <outputDirectory>${project.basedir}/temp-properties-files-for-site</outputDirectory>
+ <resources>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>${enforcer.version}</version>
+ <executions>
+ <execution>
+ <id>enforce-versions</id>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <requireMavenVersion>
+ <version>3.0.5</version>
+ </requireMavenVersion>
+ </rules>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>${javadoc.version}</version>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <detectLinks>false</detectLinks>
+ <keywords>true</keywords>
+ <linksource>false</linksource>
+ <failOnError>true</failOnError>
+ <source>${maven.compile.sourceLevel}</source>
+ <verbose>false</verbose>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>source-jar</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ </plugin>
+ <!-- we need to tweak the maven-release-plugin for GIT -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <version>2.5.3</version>
+ <configuration>
+ <pushChanges>false</pushChanges>
+ <localCheckout>true</localCheckout>
+ <autoVersionSubmodules>true</autoVersionSubmodules>
+
+ <releaseProfiles>release</releaseProfiles>
+ <preparationGoals>clean install</preparationGoals>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.7</source>
+ <target>1.7</target>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>3.3.0</version>
@@ -291,10 +752,12 @@ under the License.
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.5</version>
<configuration>
- <source>1.7</source>
- <target>1.7</target>
+ <archive>
+ <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
</configuration>
</plugin>
</plugins>
@@ -315,7 +778,181 @@ under the License.
<!--<module>ui</module>-->
<module>osgi</module>
<module>management</module>
- <!--<module>metamodel</module>-->
+ <module>metamodel</module>
</modules>
+ <profiles>
+ <!-- The release profile. It ensures that all checks
+ will be done and everything will be build what need
+ to be build. -->
+ <profile>
+ <id>release</id>
+ <activation>
+ <property>
+ <name>release</name>
+ </property>
+ </activation>
+ <properties>
+ <enforcer.skip>false</enforcer.skip>
+ <findbugs.skip>false</findbugs.skip>
+ <maven.javadoc.skip>false</maven.javadoc.skip>
+ <rat.skip>false</rat.skip>
+ </properties>
+ </profile>
+
+ <profile>
+ <id>release-sign-artifacts</id>
+ <activation>
+ <property>
+ <name>performRelease</name>
+ <value>true</value>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-gpg-plugin</artifactId>
+ <version>1.6</version>
+ <executions>
+ <execution>
+ <id>sign-artifacts</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>sign</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <!-- Do a fast build by skipping all code analysis tools -->
+ <profile>
+ <id>fast</id>
+ <activation>
+ <property>
+ <name>fast</name>
+ </property>
+ </activation>
+
+ <properties>
+ <checkstyle.skip>true</checkstyle.skip>
+ <findbugs.skip>true</findbugs.skip>
+ <rat.skip>true</rat.skip>
+ <maven.javadoc.skip>true</maven.javadoc.skip>
+ <source.skip>true</source.skip>
+ <assembly.skipAssembly>true</assembly.skipAssembly>
+ <maven.test.skip>true</maven.test.skip>
+ </properties>
+ </profile>
+
+ <profile>
+ <id>javadoc</id>
+ <activation>
+ <property>
+ <name>javadoc</name>
+ </property>
+ </activation>
+ <properties>
+ <maven.javadoc.skip>false</maven.javadoc.skip>
+ </properties>
+ </profile>
+
+ <profile>
+ <id>java8</id>
+ <activation>
+ <jdk>[1.8,)</jdk>
+ </activation>
+ <properties>
+ <additionalparam>-Xdoclint:none</additionalparam>
+ </properties>
+ </profile>
+ </profiles>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <inherited>true</inherited>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>2.9</version>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>index</report>
+ <report>project-team</report>
+ <report>license</report>
+ <report>mailing-list</report>
+ <report>issue-tracking</report>
+ <report>scm</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>${javadoc.version}</version>
+ <configuration>
+ <notimestamp>true</notimestamp>
+ <additionalparam>-Xdoclint:none</additionalparam>
+ <detectLinks>false</detectLinks>
+ <keywords>true</keywords>
+ <linksource>false</linksource>
+ <failOnError>false</failOnError>
+ <source>${maven.compile.sourceLevel}</source>
+ <verbose>false</verbose>
+ </configuration>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>javadoc</report>
+ </reports>
+ </reportSet>
+ <reportSet>
+ <inherited>false</inherited>
+ <reports>
+ <report>aggregate</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-changes-plugin</artifactId>
+ <version>2.12</version>
+ <inherited>false</inherited>
+ <configuration>
+ <columnNames>Type,Fix Version,Key,Summary,Assignee,Status,Created</columnNames>
+ <maxEntries>200</maxEntries>
+ <onlyCurrentVersion>true</onlyCurrentVersion>
+ <resolutionIds>Fixed</resolutionIds>
+ <statusIds>Closed,Resolved</statusIds>
+ <sortColumnNames>Type</sortColumnNames>
+ <useJql>true</useJql>
+ </configuration>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>jira-report</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>${findbugs.version}</version>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
</project>
[2/5] incubator-tamaya-sandbox git commit: Added tests and bugfixes
for Tamaya OSGI support.
Posted by an...@apache.org.
Added tests and bugfixes for Tamaya OSGI support.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/f0dfa86d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/f0dfa86d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/f0dfa86d
Branch: refs/heads/master
Commit: f0dfa86dea30790ecc0d2e31f2ac62880f90a705
Parents: ff8e47c
Author: anatole <an...@apache.org>
Authored: Mon Dec 12 16:05:29 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Dec 12 16:05:29 2016 +0100
----------------------------------------------------------------------
osgi/common/pom.xml | 164 ++++++++++++++++
.../java/org/apache/tamaya/osgi/Activator.java | 130 ++++++++++++
.../tamaya/osgi/OSGIConfigRootMapper.java | 36 ++++
.../tamaya/osgi/OSGIEnhancedConfiguration.java | 117 +++++++++++
.../tamaya/osgi/TamayaConfigAdminImpl.java | 176 +++++++++++++++++
.../tamaya/osgi/TamayaOSGIConfiguration.java | 139 +++++++++++++
.../org/apache/tamaya/osgi/OSGIKarafTest.java | 115 +++++++++++
.../tamaya/osgi/TamayaConfigAdminImplTest.java | 75 +++++++
.../META-INF/javaconfiguration.properties | 21 ++
osgi/common/src/test/resources/arquillian.xml | 27 +++
osgi/common/src/test/resources/felix.properties | 23 +++
.../test/resources/org.ops4j.pax.logging.cfg | 48 +++++
osgi/features/pom.xml | 84 ++++++++
osgi/features/src/main/features/features.xml | 24 +++
osgi/pom.xml | 75 ++-----
.../java/org/apache/tamaya/osgi/Activator.java | 129 ------------
.../tamaya/osgi/OSGIConfigRootMapper.java | 36 ----
.../tamaya/osgi/OSGIEnhancedConfiguration.java | 117 -----------
.../tamaya/osgi/TamayaConfigAdminImpl.java | 196 -------------------
.../tamaya/osgi/TamayaConfigurationImpl.java | 127 ------------
.../META-INF/javaconfiguration.properties | 18 --
osgi/src/test/resources/arquillian.xml | 27 ---
osgi/src/test/resources/felix.properties | 23 ---
23 files changed, 1192 insertions(+), 735 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/pom.xml
----------------------------------------------------------------------
diff --git a/osgi/common/pom.xml b/osgi/common/pom.xml
new file mode 100644
index 0000000..c10de13
--- /dev/null
+++ b/osgi/common/pom.xml
@@ -0,0 +1,164 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+
+ <!--
+
+ 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.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-osgi-all</artifactId>
+ <version>0.3-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>tamaya-osgi</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Tamaya :: OSGi Integration :: ConfigAdmin</name>
+ <description>Tamaya Based OSGI Implementation of ConfigAdmin and Config Injection</description>
+
+ <properties>
+ <karaf.version>4.0.7</karaf.version>
+ <osgi.version>6.0.0</osgi.version>
+ <pax.exam.version>4.5.0</pax.exam.version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>bnd-maven-plugin</artifactId>
+ <version>3.3.0</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>bnd-process</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.cm</artifactId>
+ <version>1.5.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.features</groupId>
+ <artifactId>framework</artifactId>
+ <version>${karaf.version}</version>
+ <type>kar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.features</groupId>
+ <artifactId>standard</artifactId>
+ <version>${karaf.version}</version>
+ <classifier>features</classifier>
+ <type>xml</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.features</groupId>
+ <artifactId>enterprise</artifactId>
+ <version>${karaf.version}</version>
+ <classifier>features</classifier>
+ <type>xml</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${osgi.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-atinject_1.0_spec</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-functions</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-spisupport</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-osgi-features</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- Testing -->
+
+ <!--<dependency>-->
+ <!--<groupId>org.apache.tamaya.ext</groupId>-->
+ <!--<artifactId>tamaya-injection</artifactId>-->
+ <!--<version>${project.version}</version>-->
+ <!--</dependency>-->
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>java-hamcrest</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-karaf</artifactId>
+ <version>${pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit4</artifactId>
+ <version>${pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- https://mvnrepository.com/artifact/org.ops4j.pax.url/pax-url-mvn -->
+ <dependency>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-mvn</artifactId>
+ <version>1.3.7</version>
+ </dependency>
+
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java
new file mode 100644
index 0000000..1fe445c
--- /dev/null
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java
@@ -0,0 +1,130 @@
+/*
+ * 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.osgi;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.logging.Logger;
+
+/**
+ * Activator that registers the Tamaya based Service Class for {@link ConfigurationAdmin},
+ * using a default service priority of {@code 0}. This behaviour is configurable based on OSGI properties:
+ * <ul>
+ * <li><p><b>org.tamaya.integration.osgi.cm.ranking, type: int</b> allows to configure the OSGI service ranking for
+ * Tamaya based ConfigurationAdmin instance. The default ranking used is 10.</p></li>
+ * <li><p><b>org.tamaya.integration.osgi.cm.override, type: boolean</b> allows to configure if Tamaya should
+ * register its ConfigAdmin service. Default is true.</p></li>
+ * </ul>
+ */
+public class Activator implements BundleActivator {
+
+ private static final String SERVICE_RANKING_PROP = "org.apache.tamaya.osgi.cm.ranking";
+
+// private static final String SERVICE_OVERRIDE_PROP = "org.apache.tamaya.osgi.cm.override";
+
+ private static final Integer DEFAULT_RANKING = 10;
+
+ private static final Logger LOG = Logger.getLogger(Activator.class.getName());
+
+ private ServiceRegistration<ConfigurationAdmin> registration;
+
+// private ServiceTracker<Object, Object> injectionTracker;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ Dictionary<String, Object> props = new Hashtable<>();
+ String ranking = context.getProperty(SERVICE_RANKING_PROP);
+ if (ranking == null) {
+ ranking = System.getProperty(SERVICE_RANKING_PROP);
+ }
+ if (ranking == null) {
+ props.put(Constants.SERVICE_RANKING, DEFAULT_RANKING);
+ LOG.fine("Using default ranking for Tamaya OSGI ConfigAdmin service: " + DEFAULT_RANKING);
+ } else {
+ props.put(Constants.SERVICE_RANKING, Integer.valueOf(ranking));
+ LOG.fine("Using custom ranking for Tamaya OSGI ConfigAdmin service: " + ranking);
+ }
+ TamayaConfigAdminImpl cm = new TamayaConfigAdminImpl(context);
+ registration = context.registerService(ConfigurationAdmin.class, cm, props);
+ LOG.info("Registered Tamaya OSGI ConfigAdmin service-");
+
+ // register injection mechanisms, if not configured otherwise
+// val = context.getProperty(SERVICE_INJECT_PROP);
+// if(val == null || Boolean.parseBoolean(val)){
+// injectionTracker = new ServiceTracker<Object, Object>(context, Object.class, null) {
+// @Override
+// public Object addingService(ServiceReference<Object> reference) {
+// Object service = context.getService(reference);
+// Object pidObj = reference.getProperty(Constants.SERVICE_PID);
+// if (pidObj instanceof String) {
+// String pid = (String) pidObj;
+// ConfigurationAdmin configAdmin = null;
+// ServiceReference<ConfigurationAdmin> adminRef =
+// context.getServiceReference(ConfigurationAdmin.class);
+// if(adminRef!=null){
+// configAdmin = context.getService(adminRef);
+// }
+// try {
+// Configuration targetConfig = null;
+// if(configAdmin != null){
+// org.osgi.service.cm.Configuration osgiConfig = configAdmin.getConfiguration(pid);
+// if(osgiConfig!=null){
+// targetConfig = new OSGIEnhancedConfiguration(osgiConfig);
+// }
+// }
+// if(targetConfig==null){
+// targetConfig = ConfigurationProvider.getConfiguration();
+// }
+// ConfigurationInjection.getConfigurationInjector().configure(service, targetConfig);
+// } catch (Exception e) {
+// LOG.log(Level.WARNING, "Error configuring Service: " + service, e);
+// }
+// } else {
+// LOG.log(Level.SEVERE, "Unsupported pid: " + pidObj);
+// }
+// return service;
+// }
+//
+// @Override
+// public void removedService(ServiceReference<Object> reference, Object service) {
+// context.ungetService(reference);
+// }
+// };
+// injectionTracker.open();
+// }
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ if (registration != null) {
+ registration.unregister();
+ }
+// if(injectionTracker!=null){
+// injectionTracker.close();
+// }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java
new file mode 100644
index 0000000..79cc387
--- /dev/null
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java
@@ -0,0 +1,36 @@
+/*
+ * 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.osgi;
+
+/**
+ * Mapping function for mapping Tamaya configuration sections to OSGI pids.
+ */
+public interface OSGIConfigRootMapper {
+
+ /**
+ * Map the given OSGI pid to a corresponding configuration section in Tamaya. Es an example (and this is also the
+ * default implemented) a configuration mapping for {@code pid/factoryPid==myBundle} could be {@code [bundle:myBundle]}.
+ * This mapping is used as a prefix when collecting the corresponding entries for the OSGI configuration.
+ * @param pid the OSGI pid, or null
+ * @param factoryPid the OSGI factoryPid, or null
+ * @return return the corresponding config root section. For ommitting any root section simply return an empty
+ * String.
+ */
+ String getTamayaConfigRoot(String pid, String factoryPid);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java
new file mode 100644
index 0000000..117ae1b
--- /dev/null
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java
@@ -0,0 +1,117 @@
+///*
+// * 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.osgi;
+//
+//import org.apache.tamaya.spi.PropertySource;
+//import org.apache.tamaya.spisupport.BasePropertySource;
+//import org.apache.tamaya.spisupport.DefaultConfiguration;
+//import org.apache.tamaya.spisupport.DefaultConfigurationContext;
+//
+//import java.util.Dictionary;
+//import java.util.Enumeration;
+//import java.util.HashMap;
+//import java.util.List;
+//import java.util.Map;
+//import java.util.Objects;
+//
+///**
+// * Configuration object that also reflects the values provided by the OSGI ConfigAdmin Configuration.
+// * Similar to other tamaya areas adding a tamaya.ordinal into the corresponding OSGI configuration for
+// * a pif/factoryPid allows to control the ordinal/priority of the OSGI configuration related to other
+// * configured Tamaya Property Sources. Overall the configuration evaluation for Tamaya follows the
+// * same rules, with the difference that each bunldle owns its own ConfigAdmin based part. From
+// * Tamaya, the granularity depends on the implementation of the ConfigurationProviderSpi. By default
+// * Tamaya configuration is managed as a global resource/config tree, wheres bundle specific sections are
+// * selected only.
+// */
+//public class OSGIEnhancedConfiguration extends DefaultConfiguration{
+// /** The default ordinal used for the OSGI config, */
+// private static final int OSGI_DEFAULT_ORDINAL = 0;
+//
+// /**
+// * Constructor.
+// *
+// * @param osgiConfiguration The OSGI configuration found.
+// */
+// public OSGIEnhancedConfiguration(org.osgi.service.cm.Configuration osgiConfiguration) {
+// super(new OSGIConfigurationContext(osgiConfiguration));
+// }
+//
+// /**
+// * Class that models a Tamaya ConfigurationContext, which implicitly contains the bundle specific
+// * Configuration wrapped into a Tamaya PropertySource.
+// */
+// private static final class OSGIConfigurationContext extends DefaultConfigurationContext{
+// private OSGIPropertySource osgiPropertySource;
+//
+// public OSGIConfigurationContext(org.osgi.service.cm.Configuration osgiConfiguration){
+// if(osgiConfiguration!=null) {
+// this.osgiPropertySource = new OSGIPropertySource(osgiConfiguration);
+// }
+// }
+//
+// @Override
+// public List<PropertySource> getPropertySources() {
+// List<PropertySource> sources = super.getPropertySources();
+// if(osgiPropertySource!=null){
+// sources.add(osgiPropertySource);
+// }
+// return sources;
+// }
+// }
+//
+// /**
+// * Tamaya PropertySource providing the values from an OSGI Configuration.
+// */
+// private static final class OSGIPropertySource extends BasePropertySource{
+//
+// private final org.osgi.service.cm.Configuration osgiConfiguration;
+//
+// public OSGIPropertySource(org.osgi.service.cm.Configuration osgiConfiguration){
+// this.osgiConfiguration = Objects.requireNonNull(osgiConfiguration);
+// }
+//
+// @Override
+// public int getDefaultOrdinal() {
+// String val = System.getProperty("osgi.defaultOrdinal");
+// if(val!=null){
+// return Integer.parseInt(val.trim());
+// }
+// return OSGI_DEFAULT_ORDINAL;
+// }
+//
+// @Override
+// public String getName() {
+// return "OSGIConfig:pid="+
+// (osgiConfiguration.getPid()!=null?osgiConfiguration.getPid():osgiConfiguration.getFactoryPid());
+// }
+//
+// @Override
+// public Map<String, String> getProperties() {
+// Map<String, String> map = new HashMap<>();
+// Dictionary<String,Object> dict = osgiConfiguration.getProperties();
+// Enumeration<String> keys = dict.keys();
+// while(keys.hasMoreElements()){
+// String key = keys.nextElement();
+// map.put(key,String.valueOf(dict.get(key)));
+// }
+// return map;
+// }
+// }
+//}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java
new file mode 100644
index 0000000..047cfb3
--- /dev/null
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java
@@ -0,0 +1,176 @@
+/*
+ * 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.osgi;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/**
+ * Tamaya based implementation of an OSGI {@link ConfigurationAdmin}.
+ */
+public class TamayaConfigAdminImpl implements ConfigurationAdmin {
+ /** the logger. */
+ private static final Logger LOG = Logger.getLogger(TamayaConfigAdminImpl.class.getName());
+
+ /** The OSGI context. */
+ private final BundleContext context;
+ /** THe optional OSGI parent service. */
+ private ConfigurationAdmin parent;
+ /** The cached configurations. */
+ private Map<String,Configuration> configs = new WeakHashMap<>();
+ /** The configuration section mapper. */
+ private OSGIConfigRootMapper configRootMapper;
+
+ /**
+ * Create a new config.
+ * @param context the OSGI context
+ */
+ TamayaConfigAdminImpl(BundleContext context) {
+ this.context = context;
+ this.configRootMapper = loadConfigRootMapper();
+ }
+
+ @Override
+ public Configuration createFactoryConfiguration(String factoryPid) throws IOException {
+ return createFactoryConfiguration(factoryPid, null);
+ }
+
+ @Override
+ public Configuration createFactoryConfiguration(String factoryPid, String location) throws IOException {
+ String key = "factory:"+factoryPid;
+ if(location!=null){
+ key += "::"+location;
+ }
+ Configuration config = this.configs.get(key);
+ if(config==null) {
+ Dictionary<String, Object> parentConfig = getParentConfig(null, factoryPid, location);
+ config = new TamayaOSGIConfiguration(null, factoryPid, configRootMapper, parentConfig);
+ this.configs.put(key, config);
+ }
+ return config;
+ }
+
+ @Override
+ public Configuration getConfiguration(String pid, String location) throws IOException {
+ String key = "config:"+pid;
+ if(location!=null){
+ key += "::"+location;
+ }
+ Configuration config = this.configs.get(key);
+ if(config==null) {
+ Dictionary<String, Object> parentConfig = getParentConfig(pid, null, location);
+ config = new TamayaOSGIConfiguration(pid, null, configRootMapper, parentConfig);
+ this.configs.put(key, config);
+ }
+ return config;
+ }
+
+ @Override
+ public Configuration getConfiguration(String pid) throws IOException {
+ return getConfiguration(pid, null);
+ }
+
+ private Dictionary<String, Object> getParentConfig(String pid, String factoryPid, String location) {
+ Dictionary<String, Object> parentConfig = null;
+ if (context != null) {
+ try {
+ ServiceReference[] refs = context.getAllServiceReferences(ConfigurationAdmin.class.getName(), null);
+ for (ServiceReference<ConfigurationAdmin> ref : refs) {
+ ConfigurationAdmin parentCand = context.getService(ref);
+ if (parentCand != null && !(parentCand instanceof TamayaConfigAdminImpl)) {
+ try {
+ parentConfig = parentCand.getConfiguration(pid, factoryPid).getProperties();
+ } catch (IOException e) {
+ LOG.log(Level.WARNING, "Error reading parent OSGI config.", e);
+ }
+ }
+ }
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Cannot not evaluate parent/base OSGI config.", e);
+ }
+ }
+ return parentConfig;
+ }
+
+ @Override
+ public Configuration[] listConfigurations(String filter) throws IOException, InvalidSyntaxException {
+ Collection<Configuration> result;
+ if (filter == null) {
+ result = this.configs.values();
+ } else {
+ result = new ArrayList<>();
+ if(context==null){
+ for (Configuration config : this.configs.values()) {
+ result.add(config);
+ }
+ }else {
+ Filter flt = context.createFilter(filter);
+ for (Configuration config : this.configs.values()) {
+ if (flt.match(config.getProperties())) {
+ result.add(config);
+ }
+ }
+ }
+ }
+ return result.toArray(new Configuration[configs.size()]);
+ }
+
+ /**
+ * Loads the configuration toor mapper using the OSGIConfigRootMapper OSGI service resolving mechanism. If no
+ * such service is available it loads the default mapper.
+ * @return the mapper to be used, bever null.
+ */
+ private OSGIConfigRootMapper loadConfigRootMapper() {
+ OSGIConfigRootMapper mapper = null;
+ if(context!=null) {
+ ServiceReference<OSGIConfigRootMapper> ref = context.getServiceReference(OSGIConfigRootMapper.class);
+ if (ref != null) {
+ mapper = context.getService(ref);
+ }
+ }
+ if(mapper==null){
+ mapper = new OSGIConfigRootMapper() {
+ @Override
+ public String getTamayaConfigRoot(String pid, String factoryPid) {
+ if(pid!=null) {
+ return "[" + pid +']';
+ } else{
+ return "[" + factoryPid +']';
+ }
+ }
+ @Override
+ public String toString(){
+ return "Default OSGIConfigRootMapper(pid -> [bundle:pid], factoryPid -> [bundle:factoryPid]";
+ }
+ };
+ }
+ return mapper;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaOSGIConfiguration.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaOSGIConfiguration.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaOSGIConfiguration.java
new file mode 100644
index 0000000..962cc38
--- /dev/null
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaOSGIConfiguration.java
@@ -0,0 +1,139 @@
+/*
+ * 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.osgi;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.logging.Logger;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.functions.ConfigurationFunctions;
+import org.osgi.service.cm.Configuration;
+
+/**
+ * Tamaya based implementation of an OSGI {@link Configuration}.
+ */
+public class TamayaOSGIConfiguration implements Configuration {
+ private static final Logger LOG = Logger.getLogger(TamayaOSGIConfiguration.class.getName());
+ private final Dictionary<String, Object> parentConfig;
+ private final String pid;
+ private final String factoryPid;
+ private OSGIConfigRootMapper rootMapper;
+ private boolean overriding = true;
+ private String bundleLocation;
+
+ /**
+ * Constructor.
+ * @param confPid the OSGI pid
+ * @param factoryPid the factory pid
+ * @param configRootMapper the mapper that maps the pids to a tamaya root section.
+ * @param parentConfig the OSGI config for the given context, may be null..
+ */
+ TamayaOSGIConfiguration(String confPid, String factoryPid, OSGIConfigRootMapper configRootMapper,
+ Dictionary<String, Object> parentConfig) {
+ this.pid = confPid;
+ this.factoryPid = factoryPid;
+ this.parentConfig = parentConfig;
+ this.rootMapper = Objects.requireNonNull(configRootMapper);
+ }
+
+ public boolean isOverriding() {
+ return overriding;
+ }
+
+ public void setOverriding(boolean overriding){
+ this.overriding = overriding;
+ }
+
+ @Override
+ public String getPid() {
+ return pid;
+ }
+
+ @Override
+ public Dictionary<String, Object> getProperties() {
+ Dictionary<String, Object> properties = new Hashtable<>();
+
+ final String rootKey = this.rootMapper.getTamayaConfigRoot(pid, factoryPid);
+ LOG.info("Configuration: Evaluating Tamaya configuration for '" + rootKey + "'.");
+ org.apache.tamaya.Configuration tamayConfig = ConfigurationProvider.getConfiguration();
+ if(overriding){
+ if(parentConfig!=null) {
+ putAll(properties, parentConfig);
+ }
+ putAll(properties, tamayConfig.with(ConfigurationFunctions.section(rootKey, true)).getProperties());
+ }else{
+ putAll(properties, tamayConfig.with(ConfigurationFunctions.section(rootKey, true)).getProperties());
+ if(parentConfig!=null) {
+ putAll(properties, parentConfig);
+ }
+ }
+ return properties;
+ }
+
+ private void putAll(Dictionary<String, Object> target, Dictionary<String, Object> data) {
+ Enumeration<String> keys = data.keys();
+ while(keys.hasMoreElements()){
+ String key = keys.nextElement();
+ target.put(key, data.get(key));
+ }
+ }
+
+ private void putAll(Dictionary<String, Object> target, Map<String, String> data) {
+ for(Map.Entry<String,String> en:data.entrySet()){
+ target.put(en.getKey(), en.getValue());
+ }
+ }
+
+ @Override
+ public void update(Dictionary<String, ?> properties) throws IOException {
+ throw new UnsupportedOperationException("Mutability is not supported.");
+ }
+
+ @Override
+ public void delete() throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getFactoryPid() {
+ return factoryPid;
+ }
+
+ @Override
+ public void update() throws IOException {
+ // Nothing to do since, we load everything dynamically.
+ }
+
+ @Override
+ public void setBundleLocation(String location) {
+ this.bundleLocation = location;
+ }
+
+ @Override
+ public String getBundleLocation() {
+ return this.bundleLocation;
+ }
+
+ @Override
+ public long getChangeCount() {
+ return 0;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java
new file mode 100644
index 0000000..d1014ef
--- /dev/null
+++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java
@@ -0,0 +1,115 @@
+/*
+ * 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.osgi;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.karaf.options.KarafDistributionOption;
+import org.ops4j.pax.exam.options.BootClasspathLibraryOption;
+import org.ops4j.pax.exam.options.MavenUrlReference;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerMethod;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import javax.inject.Inject;
+import java.io.File;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.ops4j.pax.exam.CoreOptions.*;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerMethod.class)
+public class OSGIKarafTest {
+
+ @Inject
+ private ConfigurationAdmin configAdmin;
+
+ @Configuration
+ public Option[] config() {
+ return options(
+ // distribution to test: Karaf 3.0.3
+ KarafDistributionOption.karafDistributionConfiguration()
+ .frameworkUrl(CoreOptions.maven()
+ .groupId("org.apache.karaf")
+ .artifactId("apache-karaf")
+ .type("zip")
+ .version(getKarafVersion()))
+ .karafVersion(getKarafVersion())
+ .name("ApacheKaraf")
+ .useDeployFolder(false)
+ .unpackDirectory(new File("target/karaf")),
+ // no local and remote consoles
+// KarafDistributionOption.debugConfiguration("5005", true),
+ KarafDistributionOption.configureConsole().startLocalConsole(),
+ KarafDistributionOption.configureConsole().ignoreRemoteShell(),
+ // keep runtime folder allowing analysing results
+ KarafDistributionOption.keepRuntimeFolder(),
+ // use custom logging configuration file with a custom appender
+ KarafDistributionOption.replaceConfigurationFile("etc/org.ops4j.pax.logging.cfg", new File(
+ "src/test/resources/org.ops4j.pax.logging.cfg")),
+
+ mavenBundle("org.apache.geronimo.specs", "geronimo-annotation_1.2_spec", "1.0-alpha-1"),
+ mavenBundle("org.apache.tamaya", "tamaya-api", "0.3-incubating-SNAPSHOT"),
+ mavenBundle("org.apache.tamaya", "tamaya-core", "0.3-incubating-SNAPSHOT"),
+ mavenBundle("org.apache.tamaya.ext", "tamaya-spisupport", "0.3-incubating-SNAPSHOT"),
+ mavenBundle("org.apache.tamaya.ext", "tamaya-functions", "0.3-incubating-SNAPSHOT"),
+ mavenBundle("org.apache.tamaya.ext", "tamaya-osgi", "0.3-incubating-SNAPSHOT"),
+ KarafDistributionOption.features(
+ maven().groupId("org.apache.karaf.features").artifactId("standard").type("xml")
+ .classifier("features").version(getKarafVersion()), "aries-blueprint"),
+// KarafDistributionOption.features(
+// "mvn:org.apache.karaf.features/standard/4.0.7/xml/features",
+// "aries-blueprint"),
+// bundle("reference:file:target/test-classes"),
+ junitBundles()
+ );
+ }
+
+ private String getKarafVersion() {
+ return "4.0.7";
+ }
+
+
+ @Test
+ @Ignore
+ public void ensureEnvironmentIsWorkingAndTamayaIsActive() {
+ assertNotNull(configAdmin);
+ assertTrue(configAdmin instanceof TamayaConfigAdminImpl);
+ }
+
+ @Test
+ @Ignore
+ public void getConfiguration() throws Exception {
+ org.osgi.service.cm.Configuration config = configAdmin.getConfiguration("tamaya");
+ assertNotNull(config);
+ assertFalse(config.getProperties().isEmpty());
+ assertEquals(config.getProperties().size(), 4);
+ assertEquals(config.getProperties().get("my.testProperty1"), "success1");
+ assertEquals(config.getProperties().get("my.testProperty2"), "success2");
+ assertEquals(config.getProperties().get("my.testProperty3"), "success3");
+ assertEquals(config.getProperties().get("my.testProperty4"), "success4");
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigAdminImplTest.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigAdminImplTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigAdminImplTest.java
new file mode 100644
index 0000000..93f98d0
--- /dev/null
+++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigAdminImplTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.osgi;
+
+import org.junit.Test;
+import org.osgi.service.cm.Configuration;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by atsticks on 10.12.16.
+ */
+public class TamayaConfigAdminImplTest {
+
+ private TamayaConfigAdminImpl configAdmin = new TamayaConfigAdminImpl(null);
+
+ @Test
+ public void createFactoryConfiguration() throws Exception {
+ Configuration config = configAdmin.createFactoryConfiguration("tamaya");
+ assertNotNull(config);
+ assertFalse(config.getProperties().isEmpty());
+ assertEquals(config.getProperties().size(), 4);
+ assertEquals(config.getProperties().get("my.testProperty1"), "success1");
+ }
+
+ @Test
+ public void createFactoryConfigurationWithLocation() throws Exception {
+ Configuration config = configAdmin.createFactoryConfiguration("tamaya", "location");
+ assertNotNull(config);
+ assertFalse(config.getProperties().isEmpty());
+ assertEquals(config.getProperties().size(), 4);
+ assertEquals(config.getProperties().get("my.testProperty2"), "success2");
+ }
+
+ @Test
+ public void getConfiguration() throws Exception {
+ Configuration config = configAdmin.getConfiguration("tamaya");
+ assertNotNull(config);
+ assertFalse(config.getProperties().isEmpty());
+ assertEquals(config.getProperties().size(), 4);
+ assertEquals(config.getProperties().get("my.testProperty3"), "success3");
+ }
+
+ @Test
+ public void getConfigurationWithLocation() throws Exception {
+ Configuration config = configAdmin.getConfiguration("tamaya", "location");
+ assertNotNull(config);
+ assertFalse(config.getProperties().isEmpty());
+ assertEquals(config.getProperties().size(), 4);
+ assertEquals(config.getProperties().get("my.testProperty4"), "success4");
+ }
+
+ @Test
+ public void listConfigurations() throws Exception {
+ Configuration[] configs = configAdmin.listConfigurations(".*");
+ assertNotNull(configs);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/resources/META-INF/javaconfiguration.properties b/osgi/common/src/test/resources/META-INF/javaconfiguration.properties
new file mode 100644
index 0000000..f2879a0
--- /dev/null
+++ b/osgi/common/src/test/resources/META-INF/javaconfiguration.properties
@@ -0,0 +1,21 @@
+# 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.
+#
+[tamaya]my.testProperty1=success1
+[tamaya]my.testProperty2=success2
+[tamaya]my.testProperty3=success3
+[tamaya]my.testProperty4=success4
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/resources/arquillian.xml b/osgi/common/src/test/resources/arquillian.xml
new file mode 100644
index 0000000..a4c885a
--- /dev/null
+++ b/osgi/common/src/test/resources/arquillian.xml
@@ -0,0 +1,27 @@
+<!--
+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.
+-->
+<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+
+ <container qualifier="osgi" default="true">
+ <configuration>
+ <property name="frameworkProperties">src/test/resources/felix.properties</property>
+ </configuration>
+ </container>
+</arquillian>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/test/resources/felix.properties
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/resources/felix.properties b/osgi/common/src/test/resources/felix.properties
new file mode 100644
index 0000000..4630fa2
--- /dev/null
+++ b/osgi/common/src/test/resources/felix.properties
@@ -0,0 +1,23 @@
+# 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.
+#
+# org.osgi.service.cm;org.apache.felix.cm;org.apache.tamaya;org.apache.tamaya.spi;
+org.osgi.framework.bootdelegation=org.apache.tamaya,org.apache.tamaya.osgi,org.apache.tamaya.osgi.test
+felix.log.level=4 #debug logging
+# felix.auto.deploy.dir=../test-bundles
+org.osgi.framework.storage=target/felix-cache
+felix.fileinstall.dir=./test-bundles
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/test/resources/org.ops4j.pax.logging.cfg
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/resources/org.ops4j.pax.logging.cfg b/osgi/common/src/test/resources/org.ops4j.pax.logging.cfg
new file mode 100644
index 0000000..6683438
--- /dev/null
+++ b/osgi/common/src/test/resources/org.ops4j.pax.logging.cfg
@@ -0,0 +1,48 @@
+# 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.
+#
+#updated by pax-exam
+#Sun Nov 27 20:55:11 CET 2016
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.sift.appender.append=true
+log4j.appender.out.maxFileSize=1MB
+log4j.appender.audit.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
+log4j.appender.sift.appender.file=${karaf.data}/log/$\\{bundle.name\\}.log
+log4j.appender.sift.appender.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.append=true
+log4j.appender.sift.appender=org.apache.log4j.FileAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out=org.apache.log4j.RollingFileAppender
+log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
+log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer
+log4j.appender.out.file=${karaf.data}/log/karaf.log
+log4j.appender.sift=org.apache.log4j.sift.MDCSiftingAppender
+log4j.appender.audit.append=true
+log4j.appender.audit.maxBackupIndex=10
+log4j.appender.audit.layout=org.apache.log4j.PatternLayout
+log4j.appender.sift.key=bundle.name
+log4j.appender.audit.maxFileSize=1MB
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.additivity.org.apache.karaf.jaas.modules.audit=false
+log4j.logger.org.apache.karaf.jaas.modules.audit=INFO, audit
+log4j.appender.audit.file=${karaf.data}/security/audit.log
+log4j.appender.sift.default=karaf
+log4j.appender.sift.appender.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %m%n
+log4j.appender.out.maxBackupIndex=10
+log4j.appender.audit=org.apache.log4j.RollingFileAppender
+log4j.rootLogger=WARN, out, stdout, osgi\:*
+log4j.appender.out.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/features/pom.xml
----------------------------------------------------------------------
diff --git a/osgi/features/pom.xml b/osgi/features/pom.xml
new file mode 100644
index 0000000..e7ea3eb
--- /dev/null
+++ b/osgi/features/pom.xml
@@ -0,0 +1,84 @@
+<?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 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.
+-->
+
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-sandbox</artifactId>
+ <version>0.3-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>tamaya-osgi-features</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Tamaya :: OSGI Integration :: Features</name>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>features</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <configuration>
+ <resources>
+ <resource>
+ <directory>src/main/features</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ <outputDirectory>target/features</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-artifacts</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attach-artifact</goal>
+ </goals>
+ <configuration>
+ <artifacts>
+ <artifact>
+ <file>target/features/features.xml</file>
+ <type>xml</type>
+ <classifier>features</classifier>
+ </artifact>
+ </artifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/features/src/main/features/features.xml
----------------------------------------------------------------------
diff --git a/osgi/features/src/main/features/features.xml b/osgi/features/src/main/features/features.xml
new file mode 100644
index 0000000..0655d30
--- /dev/null
+++ b/osgi/features/src/main/features/features.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 David Valeri.
+ Licensed 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.
+ -->
+<features name="org-apache-tamaya-${project.version}">
+ <feature name="org-apache-tamaya" version="${project.version}">
+ <feature>org-apache-tamaya</feature>
+ <bundle>mvn:${project.groupId}/tamaya-osgi/${project.version}/jar</bundle>
+ <bundle>mvn:${project.groupId}/tamaya-functions/${project.version}/jar</bundle>
+ <bundle>mvn:${project.groupId}/tamaya-spi-support/${project.version}/jar</bundle>
+ <bundle>mvn:org.apache.tamaya/tamaya-api/${project.version}/jar</bundle>
+ <bundle>mvn:org.apache.tamaya/tamaya-core/${project.version}/jar</bundle>
+ <bundle>mvn:org.apache.geronimo.specs/geronimo-annotation_1.2_spec/1.0-alpha-1/jar</bundle>
+ </feature>
+</features>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/pom.xml
----------------------------------------------------------------------
diff --git a/osgi/pom.xml b/osgi/pom.xml
index 193abca..1578a16 100644
--- a/osgi/pom.xml
+++ b/osgi/pom.xml
@@ -28,10 +28,10 @@
<relativePath>..</relativePath>
</parent>
- <artifactId>tamaya-osgi</artifactId>
- <packaging>jar</packaging>
- <name>Apache Tamaya Integration - OSGi Services :: Tamaya Config</name>
- <description>Tamaya Based OSGI Implementation of ConfigAdmin and Config Injection</description>
+ <artifactId>tamaya-osgi-all</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Tamaya :: OSGi Integration :: ALL</name>
+ <description>Tamaya OSGI Integration</description>
<properties>
<karaf.version>4.0.7</karaf.version>
@@ -40,29 +40,19 @@
</properties>
<dependencies>
- <!--<dependency>-->
- <!--<groupId>org.apache.felix</groupId>-->
- <!--<artifactId>org.apache.felix.configadmin</artifactId>-->
- <!--<version>1.8.8</version>-->
- <!--</dependency>-->
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.cm</artifactId>
- <version>1.5.0</version>
- </dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>${osgi.version}</version>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
+ <artifactId>tamaya-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@@ -75,50 +65,11 @@
<artifactId>tamaya-spisupport</artifactId>
<version>${project.version}</version>
</dependency>
-
- <!-- Testing -->
-
- <!--<dependency>-->
- <!--<groupId>org.apache.tamaya.ext</groupId>-->
- <!--<artifactId>tamaya-injection</artifactId>-->
- <!--<version>${project.version}</version>-->
- <!--</dependency>-->
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>java-hamcrest</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-container-karaf</artifactId>
- <version>${pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-junit4</artifactId>
- <version>${pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- <!-- https://mvnrepository.com/artifact/org.ops4j.pax.url/pax-url-mvn -->
- <dependency>
- <groupId>org.ops4j.pax.url</groupId>
- <artifactId>pax-url-mvn</artifactId>
- <version>1.3.7</version>
- </dependency>
-
-
- <!--<dependency>-->
- <!--<groupId>org.apache.karaf</groupId>-->
- <!--<artifactId>apache-karaf</artifactId>-->
- <!--<version>${karaf.version}</version>-->
- <!--<type>zip</type>-->
- <!--<scope>test</scope>-->
- <!--</dependency>-->
-
</dependencies>
+ <modules>
+ <module>features</module>
+ <module>common</module>
+ </modules>
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/src/main/java/org/apache/tamaya/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/osgi/src/main/java/org/apache/tamaya/osgi/Activator.java b/osgi/src/main/java/org/apache/tamaya/osgi/Activator.java
deleted file mode 100644
index 73820f5..0000000
--- a/osgi/src/main/java/org/apache/tamaya/osgi/Activator.java
+++ /dev/null
@@ -1,129 +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.osgi;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.util.tracker.ServiceTracker;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.logging.Logger;
-
-/**
- * Activator that registers the Tamaya based Service Class for {@link ConfigurationAdmin},
- * using a default service priority of {@code 0}. This behaviour is configurable based on OSGI properties:
- * <ul>
- * <li><p><b>org.tamaya.integration.osgi.cm.ranking, type: int</b> allows to configure the OSGI service ranking for
- * Tamaya based ConfigurationAdmin instance. The default ranking used is 10.</p></li>
- * <li><p><b>org.tamaya.integration.osgi.cm.override, type: boolean</b> allows to configure if Tamaya should
- * register its ConfigAdmin service. Default is true.</p></li>
- * </ul>
- */
-public class Activator implements BundleActivator {
-
- private static final String SERVICE_RANKING_PROP = "org.tamaya.integration.osgi.cm.ranking";
-
- private static final String SERVICE_OVERRIDE_PROP = "org.tamaya.integration.osgi.cm.override";
-
- private static final String SERVICE_INJECT_PROP = "org.tamaya.integration.osgi.cm.inject";
-
- private static final Integer DEFAULT_RANKING = 10;
-
- private static final Logger LOG = Logger.getLogger(Activator.class.getName());
-
- private ServiceRegistration<ConfigurationAdmin> registration;
-
- private ServiceTracker<Object, Object> injectionTracker;
-
- @Override
- public void start(BundleContext context) throws Exception {
- String val = context.getProperty(SERVICE_OVERRIDE_PROP);
- if(val == null || Boolean.parseBoolean(val)){
- Dictionary<String, Object> props = new Hashtable<>();
- String ranking = context.getProperty(SERVICE_RANKING_PROP);
- if (ranking == null) {
- props.put(Constants.SERVICE_RANKING, DEFAULT_RANKING);
- } else {
- props.put(Constants.SERVICE_RANKING, Integer.valueOf(ranking));
- }
- TamayaConfigAdminImpl cm = new TamayaConfigAdminImpl(context);
- registration = context.registerService(ConfigurationAdmin.class, cm, props);
- }
-
- // register injection mechanisms, if not configured otherwise
-// val = context.getProperty(SERVICE_INJECT_PROP);
-// if(val == null || Boolean.parseBoolean(val)){
-// injectionTracker = new ServiceTracker<Object, Object>(context, Object.class, null) {
-// @Override
-// public Object addingService(ServiceReference<Object> reference) {
-// Object service = context.getService(reference);
-// Object pidObj = reference.getProperty(Constants.SERVICE_PID);
-// if (pidObj instanceof String) {
-// String pid = (String) pidObj;
-// ConfigurationAdmin configAdmin = null;
-// ServiceReference<ConfigurationAdmin> adminRef =
-// context.getServiceReference(ConfigurationAdmin.class);
-// if(adminRef!=null){
-// configAdmin = context.getService(adminRef);
-// }
-// try {
-// Configuration targetConfig = null;
-// if(configAdmin != null){
-// org.osgi.service.cm.Configuration osgiConfig = configAdmin.getConfiguration(pid);
-// if(osgiConfig!=null){
-// targetConfig = new OSGIEnhancedConfiguration(osgiConfig);
-// }
-// }
-// if(targetConfig==null){
-// targetConfig = ConfigurationProvider.getConfiguration();
-// }
-// ConfigurationInjection.getConfigurationInjector().configure(service, targetConfig);
-// } catch (Exception e) {
-// LOG.log(Level.WARNING, "Error configuring Service: " + service, e);
-// }
-// } else {
-// LOG.log(Level.SEVERE, "Unsupported pid: " + pidObj);
-// }
-// return service;
-// }
-//
-// @Override
-// public void removedService(ServiceReference<Object> reference, Object service) {
-// context.ungetService(reference);
-// }
-// };
-// injectionTracker.open();
-// }
- }
-
- @Override
- public void stop(BundleContext context) throws Exception {
- if (registration != null) {
- registration.unregister();
- }
- if(injectionTracker!=null){
- injectionTracker.close();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java
----------------------------------------------------------------------
diff --git a/osgi/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java b/osgi/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java
deleted file mode 100644
index 79cc387..0000000
--- a/osgi/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java
+++ /dev/null
@@ -1,36 +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.osgi;
-
-/**
- * Mapping function for mapping Tamaya configuration sections to OSGI pids.
- */
-public interface OSGIConfigRootMapper {
-
- /**
- * Map the given OSGI pid to a corresponding configuration section in Tamaya. Es an example (and this is also the
- * default implemented) a configuration mapping for {@code pid/factoryPid==myBundle} could be {@code [bundle:myBundle]}.
- * This mapping is used as a prefix when collecting the corresponding entries for the OSGI configuration.
- * @param pid the OSGI pid, or null
- * @param factoryPid the OSGI factoryPid, or null
- * @return return the corresponding config root section. For ommitting any root section simply return an empty
- * String.
- */
- String getTamayaConfigRoot(String pid, String factoryPid);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java
----------------------------------------------------------------------
diff --git a/osgi/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java b/osgi/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java
deleted file mode 100644
index 66f9b1c..0000000
--- a/osgi/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java
+++ /dev/null
@@ -1,117 +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.osgi;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spisupport.BasePropertySource;
-import org.apache.tamaya.spisupport.DefaultConfiguration;
-import org.apache.tamaya.spisupport.DefaultConfigurationContext;
-
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * Configuration object that also reflects the values provided by the OSGI ConfigAdmin Configuration.
- * Similar to other tamaya areas adding a tamaya.ordinal into the corresponding OSGI configuration for
- * a pif/factoryPid allows to control the ordinal/priority of the OSGI configuration related to other
- * configured Tamaya Property Sources. Overall the configuration evaluation for Tamaya follows the
- * same rules, with the difference that each bunldle owns its own ConfigAdmin based part. From
- * Tamaya, the granularity depends on the implementation of the ConfigurationProviderSpi. By default
- * Tamaya configuration is managed as a global resource/config tree, wheres bundle specific sections are
- * selected only.
- */
-public class OSGIEnhancedConfiguration extends DefaultConfiguration{
- /** The default ordinal used for the OSGI config, */
- private static final int OSGI_DEFAULT_ORDINAL = 0;
-
- /**
- * Constructor.
- *
- * @param osgiConfiguration The OSGI configuration found.
- */
- public OSGIEnhancedConfiguration(org.osgi.service.cm.Configuration osgiConfiguration) {
- super(new OSGIConfigurationContext(osgiConfiguration));
- }
-
- /**
- * Class that models a Tamaya ConfigurationContext, which implicitly contains the bundle specific
- * Configuration wrapped into a Tamaya PropertySource.
- */
- private static final class OSGIConfigurationContext extends DefaultConfigurationContext{
- private OSGIPropertySource osgiPropertySource;
-
- public OSGIConfigurationContext(org.osgi.service.cm.Configuration osgiConfiguration){
- if(osgiConfiguration!=null) {
- this.osgiPropertySource = new OSGIPropertySource(osgiConfiguration);
- }
- }
-
- @Override
- public List<PropertySource> getPropertySources() {
- List<PropertySource> sources = super.getPropertySources();
- if(osgiPropertySource!=null){
- sources.add(osgiPropertySource);
- }
- return sources;
- }
- }
-
- /**
- * Tamaya PropertySource providing the values from an OSGI Configuration.
- */
- private static final class OSGIPropertySource extends BasePropertySource{
-
- private final org.osgi.service.cm.Configuration osgiConfiguration;
-
- public OSGIPropertySource(org.osgi.service.cm.Configuration osgiConfiguration){
- this.osgiConfiguration = Objects.requireNonNull(osgiConfiguration);
- }
-
- @Override
- public int getDefaultOrdinal() {
- String val = System.getProperty("osgi.defaultOrdinal");
- if(val!=null){
- return Integer.parseInt(val.trim());
- }
- return OSGI_DEFAULT_ORDINAL;
- }
-
- @Override
- public String getName() {
- return "OSGIConfig:pid="+
- (osgiConfiguration.getPid()!=null?osgiConfiguration.getPid():osgiConfiguration.getFactoryPid());
- }
-
- @Override
- public Map<String, String> getProperties() {
- Map<String, String> map = new HashMap<>();
- Dictionary<String,Object> dict = osgiConfiguration.getProperties();
- Enumeration<String> keys = dict.keys();
- while(keys.hasMoreElements()){
- String key = keys.nextElement();
- map.put(key,String.valueOf(dict.get(key)));
- }
- return map;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java
----------------------------------------------------------------------
diff --git a/osgi/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java b/osgi/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java
deleted file mode 100644
index 35c55e7..0000000
--- a/osgi/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java
+++ /dev/null
@@ -1,196 +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.osgi;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceFactory;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.cm.ManagedService;
-import org.osgi.service.cm.ManagedServiceFactory;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * Tamaya based implementation of an OSGI {@link ConfigurationAdmin}.
- */
-public class TamayaConfigAdminImpl implements ConfigurationAdmin {
- /** the logger. */
- private static final Logger LOG = Logger.getLogger(TamayaConfigAdminImpl.class.getName());
-
- /** The OSGI context. */
- private final BundleContext context;
- /** THe optional OSGI parent service. */
- private ConfigurationAdmin parent;
- /** The cached configurations. */
- private Map<String,Configuration> configs = new ConcurrentHashMap<>();
- /** The configuration section mapper. */
- private OSGIConfigRootMapper configRootMapper;
-
- /**
- * Create a new config.
- * @param context the OSGI context
- */
- TamayaConfigAdminImpl(BundleContext context) {
- this.context = context;
- this.configRootMapper = loadConfigRootMapper();
- ServiceReference<ConfigurationAdmin> ref = context.getServiceReference(ConfigurationAdmin.class);
- this.parent = ref!=null?context.getService(ref):null;
- ServiceTracker<ManagedService, ManagedService> serviceTracker = new ServiceTracker<ManagedService,
- ManagedService>(context, ManagedService.class, null) {
- @Override
- public ManagedService addingService(ServiceReference<ManagedService> reference) {
- ManagedService service = context.getService(reference);
- Object pidObj = reference.getProperty(Constants.SERVICE_PID);
- if (pidObj instanceof String) {
- String pid = (String) pidObj;
- try {
- Configuration config = getConfiguration(pid);
- if(config==null){
- service.updated(null);
- } else{
- service.updated(config.getProperties());
- }
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Error configuring ManagedService: " + service, e);
- }
- } else {
- LOG.log(Level.SEVERE, "Unsupported pid: " + pidObj);
- }
- return service;
- }
-
- @Override
- public void removedService(ServiceReference<ManagedService> reference, ManagedService service) {
- context.ungetService(reference);
- }
- };
- serviceTracker.open();
-
- ServiceTracker<ServiceFactory, ServiceFactory> factoryTracker
- = new ServiceTracker<ServiceFactory, ServiceFactory>(context, ServiceFactory.class, null) {
- @Override
- public ServiceFactory addingService(ServiceReference<ServiceFactory> reference) {
- ServiceFactory factory = context.getService(reference);
- if(factory instanceof ManagedServiceFactory) {
- Object pidObj = reference.getProperty(Constants.SERVICE_PID);
- if (pidObj instanceof String) {
- String pid = (String) pidObj;
- try {
- Configuration config = getConfiguration(pid);
- if (config != null) {
- ((ManagedServiceFactory) factory).updated(config.getFactoryPid(), config.getProperties());
- }
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Error configuring ManagedServiceFactory: " + factory, e);
- }
- } else {
- LOG.log(Level.SEVERE, "Unsupported pid: " + pidObj);
- }
- }
- return factory;
- }
-
- @Override
- public void removedService(ServiceReference<ServiceFactory> reference, ServiceFactory service) {
- super.removedService(reference, service);
- }
- };
- factoryTracker.open();
- }
-
- @Override
- public Configuration createFactoryConfiguration(String factoryPid) throws IOException {
- return createFactoryConfiguration(factoryPid, null);
- }
-
- @Override
- public Configuration createFactoryConfiguration(String factoryPid, String location) throws IOException {
- return new TamayaConfigurationImpl(factoryPid, null, configRootMapper, this.parent);
- }
-
- @Override
- public Configuration getConfiguration(String pid, String location) throws IOException {
- return getConfiguration(pid);
- }
-
- @Override
- public Configuration getConfiguration(String pid) throws IOException {
- return new TamayaConfigurationImpl(pid, null, configRootMapper, this.parent);
- }
-
- @Override
- public Configuration[] listConfigurations(String filter) throws IOException, InvalidSyntaxException {
- Collection<Configuration> result;
- if (filter == null) {
- result = this.configs.values();
- } else {
- result = new ArrayList<>();
- Filter flt = context.createFilter(filter);
- for (Configuration config : this.configs.values()) {
- if (flt.match(config.getProperties())) {
- result.add(config);
- }
- }
- }
- return result.isEmpty() ? null : result.toArray(new Configuration[configs.size()]);
- }
-
- /**
- * Loads the configuration toor mapper using the OSGIConfigRootMapper OSGI service resolving mechanism. If no
- * such service is available it loads the default mapper.
- * @return the mapper to be used, bever null.
- */
- private OSGIConfigRootMapper loadConfigRootMapper() {
- OSGIConfigRootMapper mapper = null;
- ServiceReference<OSGIConfigRootMapper> ref = context.getServiceReference(OSGIConfigRootMapper.class);
- if(ref!=null){
- mapper = context.getService(ref);
- }
- if(mapper==null){
- mapper = new OSGIConfigRootMapper() {
- @Override
- public String getTamayaConfigRoot(String pid, String factoryPid) {
- if(pid!=null) {
- return "[bundle:" + pid +']';
- } else{
- return "[bundle:" + factoryPid +']';
- }
- }
- @Override
- public String toString(){
- return "Default OSGIConfigRootMapper(pid -> [bundle:pid], factoryPid -> [bundle:factoryPid]";
- }
- };
- }
- return mapper;
- }
-
-}
[4/5] incubator-tamaya-sandbox git commit: Added tests for OSGI
support,
simplified OSGI support. Implemented base functionality for metamodel support,
including first testing.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentFactory.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..906b704
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentFactory.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tamaya.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;
+
+/**
+ * Small helper class for loading of configured instances.
+ */
+public final class ComponentFactory<T> {
+
+ private Class<T> type;
+ private Map<String, T> serviceContext = new HashMap<>();
+ private Set<String> loaded = new HashSet<>();
+
+ /**
+ * Constructor.
+ * @param type the service type, not null.
+ */
+ public ComponentFactory(Class<T> type){
+ this.type = Objects.requireNonNull(type);
+ for(T service: ServiceContextManager.getServiceContext().getServices(type)){
+ serviceContext.put(service.getClass().getName(), service);
+ }
+ }
+
+ /**
+ * Creates an instance of the given type based on a type configuration.
+ * Type hereby is
+ * <ul>
+ * <li>A fully qualified class name</li>
+ * <li>A simple class name of a filter class registered with the current
+ * ServiceContext.</li>
+ * </ul>
+ * @param identifier the configured type
+ * @return the component found, or null.
+ */
+ public T getComponent(String identifier)
+ throws IllegalAccessException, InstantiationException {
+ T comp = this.serviceContext.get(identifier);
+ if(comp==null){
+ for(Map.Entry<String, T> en:serviceContext.entrySet()){
+ if(en.getKey().endsWith("."+identifier)){
+ comp = en.getValue();
+ }
+ }
+ }
+ // Multiple instances: create a new instance using the parameterless constructor for all subsequent
+ // resolutions.
+ if(loaded.contains(comp.getClass().getName())){
+ return (T)comp.getClass().newInstance();
+ }
+ // Ensure that the next access will return a new instance.
+ loaded.add(comp.getClass().getName());
+ 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;
+ }
+
+ @Override
+ public String toString() {
+ return "ComponentFactory{" +
+ "type=" + type +
+ ", serviceContext=" + serviceContext +
+ '}';
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ContextReader.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ContextReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ContextReader.java
new file mode 100644
index 0000000..5754e4f
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ContextReader.java
@@ -0,0 +1,66 @@
+/*
+ * 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.spi.ConfigurationContextBuilder;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import javax.annotation.Priority;
+import java.util.logging.Logger;
+
+/**
+ * Meta-configuration reader that reads the shared context data.
+ */
+@Priority(-1)
+public class ContextReader implements MetaConfigurationReader {
+
+ private static final Logger LOG = Logger.getLogger(ContextReader.class.getName());
+
+ @Override
+ public void read(Document document, ConfigurationContextBuilder contextBuilder) {
+ NodeList nodeList = document.getDocumentElement().getElementsByTagName("context");
+ String contextName = "DEFAULT";
+ LOG.finer("Reading " + nodeList.getLength() + " meta context entries...");
+ for(int i=0;i<nodeList.getLength();i++){
+ Node node = nodeList.item(i);
+ if(node.getNodeName().equals("context")){
+ Node nameNode = node.getAttributes().getNamedItem("name");
+ if(nameNode!=null){
+ contextName = nameNode.getTextContent();
+ }
+ MetaContext context = MetaContext.getInstance(contextName);
+ NodeList entryNodes = node.getChildNodes();
+ for(int c=0;c<entryNodes.getLength();c++){
+ Node entryNode = entryNodes.item(c);
+ if("context-entry".equals(entryNode.getNodeName())){
+ String key = entryNode.getAttributes().getNamedItem("name").getNodeValue();
+ String value = entryNode.getTextContent();
+ // TODO add support for placeholders here...
+ LOG.finest("Applying context entry: " + key + '=' + value + " on " + contextName);
+ context.setProperty(key, value);
+ }
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DSLLoadingConfigurationProviderSpi.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DSLLoadingConfigurationProviderSpi.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DSLLoadingConfigurationProviderSpi.java
new file mode 100644
index 0000000..266ed5a
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DSLLoadingConfigurationProviderSpi.java
@@ -0,0 +1,114 @@
+/*
+ * 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.MetaConfiguration;
+import org.apache.tamaya.spi.*;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spisupport.DefaultConfiguration;
+import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+import javax.annotation.Priority;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Comparator;
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * ConfigurationContext that uses {@link MetaConfiguration} to configure the
+ * Tamaya configuration context.
+ */
+@Priority(10)
+public class DSLLoadingConfigurationProviderSpi implements ConfigurationProviderSpi{
+
+ private volatile Configuration config;
+ private final Object LOCK = new Object();
+
+ @Override
+ public ConfigurationContextBuilder getConfigurationContextBuilder() {
+ return ServiceContextManager.getServiceContext().getService(ConfigurationContextBuilder.class);
+ }
+
+ @Override
+ public void setConfiguration(Configuration config) {
+ this.config = Objects.requireNonNull(config);
+ }
+
+ @Override
+ public boolean isConfigurationSettable() {
+ return true;
+ }
+
+ @Override
+ public void setConfigurationContext(ConfigurationContext context){
+ this.config = Objects.requireNonNull(createConfiguration(context));
+ }
+
+ @Override
+ public boolean isConfigurationContextSettable() {
+ return true;
+ }
+
+ @Override
+ public Configuration getConfiguration() {
+ checkInitialized();
+ return config;
+ }
+
+ @Override
+ public Configuration createConfiguration(ConfigurationContext context) {
+ return new DefaultConfiguration(context);
+ }
+
+ @Override
+ public ConfigurationContext getConfigurationContext() {
+ checkInitialized();
+ return config.getContext();
+ }
+
+ private void checkInitialized() {
+ if(config==null){
+ synchronized (LOCK) {
+ if(config==null){
+ MetaConfiguration.configure();
+ }
+ if(config==null){
+ // load defaults
+ this.config = new DefaultConfiguration(
+ new DefaultConfigurationContextBuilder()
+ .addDefaultPropertyConverters()
+ .addDefaultPropertyFilters()
+ .addDefaultPropertySources()
+ .sortPropertyFilter(
+ (Comparator<PropertyFilter>)
+ DefaultConfigurationContextBuilder.DEFAULT_PROPERTYFILTER_COMPARATOR)
+ .sortPropertySources(DefaultConfigurationContextBuilder.DEFAULT_PROPERTYSOURCE_COMPARATOR)
+ .build());
+ }
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DefaultRefreshablePropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DefaultRefreshablePropertySourceProvider.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DefaultRefreshablePropertySourceProvider.java
deleted file mode 100644
index f968a15..0000000
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DefaultRefreshablePropertySourceProvider.java
+++ /dev/null
@@ -1,72 +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.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-
-import java.util.Collection;
-import java.util.Objects;
-
-/**
- * Wrapped property source that allows dynamically reassigning the property source's
- * ordinal value. This is needed for reordering the property sources to
- * match the DSL configured ordering.
- */
-public final class DefaultRefreshablePropertySourceProvider implements PropertySourceProvider, Refreshable {
-
- private SourceConfig sourceConfig;
- private PropertySourceProvider wrapped;
- private Collection<PropertySource> propertSources;
-
- public DefaultRefreshablePropertySourceProvider(SourceConfig sourceConfig)
- throws IllegalAccessException, InstantiationException,
- ClassNotFoundException {
- this.sourceConfig = Objects.requireNonNull(sourceConfig);
- this.wrapped = Objects.requireNonNull(sourceConfig.create(PropertySourceProvider.class));
- this.propertSources = Objects.requireNonNull(wrapped.getPropertySources());
- }
-
- @Override
- public Collection<PropertySource> getPropertySources() {
- return this.propertSources;
- }
-
- @Override
- public ConfigurationContext refresh(ConfigurationContext context) {
- Collection<PropertySource> newPropertySources =
- Objects.requireNonNull(wrapped.getPropertySources());
- ConfigurationContextBuilder builder = context.toBuilder();
- // remove previous sources
- builder.removePropertySources(this.propertSources);
- // add new sources
- builder.addPropertySources(newPropertySources);
- return builder.build();
- }
-
- @Override
- public String toString() {
- return "WrappedPropertySource{" +
- "sourceConfig=" + sourceConfig +
- ", wrapped=" + wrapped +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/FactoryManager.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/FactoryManager.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/FactoryManager.java
deleted file mode 100644
index a8129f6..0000000
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/FactoryManager.java
+++ /dev/null
@@ -1,140 +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.spi.PropertySourceFactory;
-import org.apache.tamaya.metamodel.spi.PropertySourceProviderFactory;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Small manager component to maintain the factories to be referenced by type names.
- */
-final class FactoryManager {
-
- private static final Logger LOG = Logger.getLogger(FactoryManager.class.getName());
- private static final FactoryManager INSTANCE = new FactoryManager();
-
- private Map<String, PropertySourceFactory> sourceFactories = new HashMap<>();
- private Map<String, PropertySourceProviderFactory> providerFactories = new HashMap<>();
-
- private FactoryManager(){
- for(PropertySourceFactory f: ServiceContextManager.getServiceContext().getServices(PropertySourceFactory.class)){
- this.sourceFactories.put(f.getType(), f);
- }
- for(PropertySourceProviderFactory f: ServiceContextManager.getServiceContext().getServices(PropertySourceProviderFactory.class)){
- this.providerFactories.put(f.getType(), f);
- }
- }
-
- public static FactoryManager getInstance(){
- return INSTANCE;
- }
-
- public PropertySourceFactory getSourceFactory(String type){
- PropertySourceFactory fact = this.sourceFactories.get(type);
- if(fact==null){
- try{
- Class<? extends PropertySource> psType = (Class<? extends PropertySource>)Class.forName(type);
- fact = new ImplicitPropertySourceFactory(psType);
- this.sourceFactories.put(type, fact);
- return fact;
- }catch(Exception e){
- LOG.log(Level.SEVERE, "Failed to load PropertySourceFactory: " + type);
- }
- }
- throw new IllegalArgumentException("No such PropertySourceFactory: " + type);
- }
-
- public PropertySourceProviderFactory getProviderFactory(String type){
- PropertySourceProviderFactory fact = this.providerFactories.get(type);
- if(fact==null){
- try{
- Class<? extends PropertySourceProvider> psType = (Class<? extends PropertySourceProvider>)Class.forName(type);
- fact = new ImplicitPropertySourceProviderFactory(psType);
- this.providerFactories.put(type, fact);
- return fact;
- }catch(Exception e){
- LOG.log(Level.SEVERE, "Failed to load PropertySourceProviderFactory: " + type);
- }
- }
- throw new IllegalArgumentException("No such PropertySourceProviderFactory: " + type);
- }
-
- @Override
- public String toString() {
- return "FactoryManager{" +
- "providerFactories=" + providerFactories.keySet() +
- ", sourceFactories=" + sourceFactories.keySet() +
- '}';
- }
-
- private static class ImplicitPropertySourceFactory implements PropertySourceFactory{
-
- private Class<? extends PropertySource> type;
-
- ImplicitPropertySourceFactory(Class<? extends PropertySource> type){
- this.type = Objects.requireNonNull(type);
- }
-
- @Override
- public PropertySource create(Map<String, String> config) {
- try {
- return this.type.newInstance();
- } catch (Exception e) {
- throw new IllegalStateException("Cannot instantiate PropertySource: " + this.type.getName(), e);
- }
- }
-
- @Override
- public String getType() {
- return null;
- }
- }
-
- private static class ImplicitPropertySourceProviderFactory implements PropertySourceProviderFactory{
-
- private Class<? extends PropertySourceProvider> type;
-
- ImplicitPropertySourceProviderFactory(Class<? extends PropertySourceProvider> type){
- this.type = Objects.requireNonNull(type);
- }
-
- @Override
- public PropertySourceProvider create(Map<String, String> config) {
- try {
- return this.type.newInstance();
- } catch (Exception e) {
- throw new IllegalStateException("Cannot instantiate PropertySourceProvider: " + this.type.getName(), e);
- }
- }
-
- @Override
- public String getType() {
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyConverterReader.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..f82e92d
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyConverterReader.java
@@ -0,0 +1,88 @@
+/*
+ * 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.TypeLiteral;
+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.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+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;
+
+/**
+ * Metaconfiguration reader to read property sources and property source providers.
+ */
+public class PropertyConverterReader implements MetaConfigurationReader{
+
+ private static final Logger LOG = Logger.getLogger(PropertyConverterReader.class.getName());
+
+ @Override
+ public void read(Document document, ConfigurationContextBuilder contextBuilder) {
+ NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-converters");
+ if(nodeList.getLength()==0){
+ LOG.finer("No property converters configured");
+ return;
+ }
+ if(nodeList.getLength()>1){
+ LOG.warning("Multiple property-converters sections configured, onyl reading first...");
+ return;
+ }
+ nodeList = nodeList.item(0).getChildNodes();
+ for(int i=0;i<nodeList.getLength();i++){
+ Node node = nodeList.item(i);
+ try{
+ if(node.getNodeName().equals("converter")){
+ String type = node.getAttributes().getNamedItem("type").getNodeValue();
+ try {
+ ItemFactory<PropertyConverter> converterFactory = ItemFactoryManager.getInstance().getFactory(PropertyConverter.class, type);
+ if(converterFactory==null){
+ LOG.severe("No such property converter: " + type);
+ continue;
+ }
+ Map<String,String> params = ComponentConfigurator.extractParameters(node);
+ PropertyConverter converter = converterFactory.create(params);
+ if(converter!=null) {
+ ComponentConfigurator.configure(converter, node);
+ Class targetType = Class.forName(params.get("targetType"));
+ LOG.finer("Adding converter for type " + targetType.getName() + ": " + converter.getClass());
+ contextBuilder.addPropertyConverters(TypeLiteral.of(targetType), converter);
+ }
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Failed to configure PropertyConverter: " + type, e);
+ }
+ }else if(node.getNodeName().equals("default-converters")){
+ LOG.finer("Adding default property converters...");
+ contextBuilder.addDefaultPropertyConverters();
+ }
+ }catch(Exception e){
+ LOG.log(Level.SEVERE, "Failed to read property converter configuration: " + node, e);
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterOrderingReader.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..818b785
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterOrderingReader.java
@@ -0,0 +1,63 @@
+/*
+ * 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.ConfigException;
+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.ConfigurationContextBuilder;
+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.logging.Logger;
+
+
+/**
+ * Metaconfiguration reader that reads the configuration combination policy to be used.
+ */
+@Priority(Integer.MAX_VALUE)
+public class PropertyFilterOrderingReader implements MetaConfigurationReader{
+
+ private static final Logger LOG = Logger.getLogger(PropertyFilterOrderingReader.class.getName());
+
+ @Override
+ public void read(Document document, ConfigurationContextBuilder contextBuilder) {
+ NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-filter-order");
+ if(nodeList.getLength()==0){
+ LOG.finer("No property filter ordering configured.");
+ return;
+ }
+ if(nodeList.getLength()>1){
+ throw new ConfigException("Only one property filter order can be applied.");
+ }
+ 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());
+ contextBuilder.sortPropertyFilter(comparator);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterReader.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..94bb6ec
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertyFilterReader.java
@@ -0,0 +1,83 @@
+/*
+ * 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.spi.ItemFactory;
+import org.apache.tamaya.metamodel.spi.ItemFactoryManager;
+import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySourceProvider;
+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;
+
+
+/**
+ * Metaconfiguration reader that reads the configuration filters to be used.
+ */
+public class PropertyFilterReader implements MetaConfigurationReader{
+
+ private static final Logger LOG = Logger.getLogger(PropertyFilterReader.class.getName());
+
+ @Override
+ public void read(Document document, ConfigurationContextBuilder contextBuilder) {
+ NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-filters");
+ if(nodeList.getLength()==0){
+ LOG.finer("No property filters configured.");
+ return;
+ }
+ if(nodeList.getLength()>1){
+ LOG.warning("Multiple property-filters sections configured, onyl reading first...");
+ return;
+ }
+ nodeList = nodeList.item(0).getChildNodes();
+ for(int i=0;i<nodeList.getLength();i++){
+ Node node = nodeList.item(i);
+ try {
+ if ("filter".equals(node.getNodeName())) {
+ String type = node.getAttributes().getNamedItem("type").getNodeValue();
+ 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());
+ contextBuilder.addPropertyFilters(filter);
+ }
+ } else if ("default-filters".equals(node.getNodeName())) {
+ LOG.finer("Adding default property filters...");
+ contextBuilder.addDefaultPropertyFilters();
+ }
+ }catch(Exception e){
+ LOG.log(Level.SEVERE, "Failed to read property filter configuration: " + node, e);
+ }
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceOrderingReader.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..b811afa
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceOrderingReader.java
@@ -0,0 +1,64 @@
+/*
+ * 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.ConfigException;
+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.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
+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.logging.Logger;
+
+
+/**
+ * Metaconfiguration reader that reads the configuration combination policy to be used.
+ */
+@Priority(Integer.MAX_VALUE)
+public class PropertySourceOrderingReader implements MetaConfigurationReader{
+
+ private static final Logger LOG = Logger.getLogger(PropertySourceOrderingReader.class.getName());
+
+ @Override
+ public void read(Document document, ConfigurationContextBuilder contextBuilder) {
+ NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-source-order");
+ if(nodeList.getLength()==0){
+ LOG.finer("No property source ordering defined.");
+ return;
+ }
+ if(nodeList.getLength()>1){
+ throw new ConfigException("Only one property source order can be applied.");
+ }
+ 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());
+ contextBuilder.sortPropertySources(comparator);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..8f42a3b
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.metamodel.internal;
+
+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.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+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;
+
+/**
+ * Metaconfiguration reader to read property sources and property source providers.
+ */
+public class PropertySourceReader implements MetaConfigurationReader{
+
+ private static final Logger LOG = Logger.getLogger(PropertySourceReader.class.getName());
+
+ @Override
+ public void read(Document document, ConfigurationContextBuilder contextBuilder) {
+ NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-sources");
+ if(nodeList.getLength()==0){
+ LOG.finer("No property sources configured.");
+ return;
+ }
+ if(nodeList.getLength()>1){
+ LOG.warning("Multiple property-sources sections configured, onyl reading first...");
+ return;
+ }
+ nodeList = nodeList.item(0).getChildNodes();
+ for(int i=0;i<nodeList.getLength();i++){
+ Node node = nodeList.item(i);
+ try{
+ if(node.getNodeName().equals("source")){
+ String type = node.getAttributes().getNamedItem("type").getNodeValue();
+ try {
+ ItemFactory<PropertySource> sourceFactory = ItemFactoryManager.getInstance().getFactory(PropertySource.class, type);
+ if(sourceFactory==null){
+ LOG.severe("No such property source: " + type);
+ continue;
+ }
+ Map<String,String> params = ComponentConfigurator.extractParameters(node);
+ PropertySource ps = sourceFactory.create(params);
+ if(ps!=null) {
+ ComponentConfigurator.configure(ps, params);
+ LOG.finer("Adding configured property source: " + ps.getName());
+ contextBuilder.addPropertySources(ps);
+ }
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Failed to configure PropertySource: " + type, e);
+ }
+ }else if(node.getNodeName().equals("source-provider")){
+ String type = node.getAttributes().getNamedItem("type").getNodeValue();
+ try {
+ ItemFactory<PropertySourceProvider> providerFactory = ItemFactoryManager.getInstance().getFactory(PropertySourceProvider.class, type);
+ if(providerFactory==null){
+ LOG.severe("No such property source provider: " + type);
+ continue;
+ }
+ Map<String,String> params = ComponentConfigurator.extractParameters(node);
+ PropertySourceProvider prov = providerFactory.create(params);
+ if(prov!=null) {
+ ComponentConfigurator.configure(prov, node);
+ LOG.finer("Adding configured property source provider: " + prov.getClass().getName());
+ contextBuilder.addPropertySources(prov.getPropertySources());
+ }
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Failed to configure PropertySourceProvider: " + type, e);
+ }
+ }else if(node.getNodeName().equals("default-sources")){
+ LOG.finer("Adding default property sources.");
+ contextBuilder.addDefaultPropertySources();
+ }
+ }catch(Exception e){
+ LOG.log(Level.SEVERE, "Failed to read property source configuration: " + node, e);
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/Refreshable.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/Refreshable.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/Refreshable.java
deleted file mode 100644
index bd0103e..0000000
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/Refreshable.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.metamodel.internal;
-
-import org.apache.tamaya.spi.ConfigurationContext;
-
-/**
- * Common interface for refreshable items.
- */
-public interface Refreshable {
-
- /**
- * Refreshes the given configuration context, by applying any changes
- * needed to reflect the change.
- * @param context the configuration context, not null.
- * @return the new configuration context. In case no changes are
- * needed or the changes could be applied implicitly, the
- * instance passed as input should be returned.
- */
- ConfigurationContext refresh(ConfigurationContext context);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/SourceConfig.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/SourceConfig.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/SourceConfig.java
index 4987111..00d823e 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/SourceConfig.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/SourceConfig.java
@@ -1,233 +1,233 @@
-/*
- * 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 java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * Resolver to resolve/map DSL related source expressions into PropertySources
- * loadable by a ConfigurationContext. Hereby the ordering of loaded property sources must be
- * honored if possible by implicitly adapting/Overriding the default ordinal for the sources
- * added.
- */
-public class SourceConfig {
-
- private boolean enabled;
- private String type;
- private String name;
- private Integer ordinal;
- private long refreshInterval;
- private Map<String,String> sourceConfiguration = new HashMap<>();
-
- private SourceConfig(Builder builder) {
- enabled = builder.enabled;
- type = builder.type;
- name = builder.name;
- refreshInterval = builder.refreshInterval;
- ordinal = builder.ordinal;
- sourceConfiguration = builder.sourceConfiguration;
- }
-
- /**
- * New builder builder.
- *
- * @param type the type
- * @return the builder
- */
- public static Builder newBuilder(String type) {
- return new Builder(type);
- }
-
- /**
- * New builder builder using this instance's settings.
- *
- * @return the builder
- */
- public Builder toBuilder() {
- Builder builder = new Builder(this.type);
- builder.enabled = this.enabled;
- builder.type = this.type;
- builder.ordinal = this.ordinal;
- builder.name = this.name;
- builder.sourceConfiguration = this.sourceConfiguration;
- return builder;
- }
-
- /**
- * Is enabled boolean.
- *
- * @return the boolean
- */
- public boolean isEnabled() {
- return enabled;
- }
-
- /**
- * Gets source configuration.
- *
- * @return the source configuration
- */
- public Map<String, String> getSourceConfiguration() {
- return sourceConfiguration;
- }
-
- /**
- * Gets type.
- *
- * @return the type
- */
- public String getType() {
- return type;
- }
-
- /**
- * Gets the current refresh interval, default is 0 meaning the property
- * source is never refreshed.
- *
- * @return the refresh interval
- */
- public long getRefreshInterval() {
- return refreshInterval;
- }
-
- /**
- * Gets name.
- *
- * @return the name
- */
- public String getName() {
- return name;
- }
-
- @Override
- public String toString() {
- return "PropertySourceConfig{" +
- "enabled=" + enabled +
- ", type='" + type + '\'' +
- ", name='" + name + '\'' +
- ", ordinal=" + ordinal +
- ", sourceConfiguration=" + sourceConfiguration +
- '}';
- }
-
-
- public <T> T create(Class<T> type)
- throws ClassNotFoundException, IllegalAccessException,
- InstantiationException {
- return (T)Class.forName(this.getType()).newInstance();
- }
-
-
- /**
- * {@code PropertySourceConfig} builder static inner class.
- */
- public static final class Builder {
- private boolean enabled;
- private String type;
- private String name;
- private Integer ordinal;
- private long refreshInterval;
- private Map<String, String> sourceConfiguration;
-
- private Builder(String type) {
- this.type = Objects.requireNonNull(type);
- if(type.trim().isEmpty()){
- throw new IllegalArgumentException("Type is empty.");
- }
- }
-
- /**
- * Sets the {@code refreshInterval} and returns a reference to this Builder so that the methods can be chained together.
- *
- * @param val the {@code refreshInterval} to set
- * @return a reference to this Builder
- */
- public Builder withRefreshInterval(long val) {
- refreshInterval = val;
- return this;
- }
-
- /**
- * Sets the {@code ordinal} and returns a reference to this Builder so that the methods can be chained together.
- *
- * @param val the {@code ordinal} to set
- * @return a reference to this Builder
- */
- public Builder withOrdinal(Integer val) {
- ordinal = val;
- return this;
- }
-
- /**
- * Sets the {@code enabled} and returns a reference to this Builder so that the methods can be chained together.
- *
- * @param val the {@code enabled} to set
- * @return a reference to this Builder
- */
- public Builder withEnabled(boolean val) {
- enabled = val;
- return this;
- }
-
- /**
- * Sets the {@code type} and returns a reference to this Builder so that the methods can be chained together.
- *
- * @param val the {@code type} to set
- * @return a reference to this Builder
- */
- public Builder withType(String val) {
- type = val;
- return this;
- }
-
- /**
- * Sets the {@code name} and returns a reference to this Builder so that the methods can be chained together.
- *
- * @param val the {@code name} to set
- * @return a reference to this Builder
- */
- public Builder withName(String val) {
- name = val;
- return this;
- }
-
- /**
- * Sets the {@code sourceConfiguration} and returns a reference to this Builder so that the methods can be chained together.
- *
- * @param val the {@code sourceConfiguration} to set
- * @return a reference to this Builder
- */
- public Builder withSourceConfiguration(Map<String, String> val) {
- sourceConfiguration = val;
- return this;
- }
-
- /**
- * Returns a {@code PropertySourceConfig} built from the parameters previously set.
- *
- * @return a {@code PropertySourceConfig} built with parameters of this {@code PropertySourceConfig.Builder}
- */
- public SourceConfig build() {
- return new SourceConfig(this);
- }
- }
-}
+///*
+// * 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 java.util.HashMap;
+//import java.util.Map;
+//import java.util.Objects;
+//
+///**
+// * Resolver to resolve/map DSL related source expressions into PropertySources
+// * loadable by a ConfigurationContext. Hereby the ordering of loaded property sources must be
+// * honored if possible by implicitly adapting/Overriding the default ordinal for the sources
+// * added.
+// */
+//public class SourceConfig {
+//
+// private boolean enabled;
+// private String type;
+// private String name;
+// private Integer ordinal;
+// private long refreshInterval;
+// private Map<String,String> sourceConfiguration = new HashMap<>();
+//
+// private SourceConfig(Builder builder) {
+// enabled = builder.enabled;
+// type = builder.type;
+// name = builder.name;
+// refreshInterval = builder.refreshInterval;
+// ordinal = builder.ordinal;
+// sourceConfiguration = builder.sourceConfiguration;
+// }
+//
+// /**
+// * New builder builder.
+// *
+// * @param type the type
+// * @return the builder
+// */
+// public static Builder newBuilder(String type) {
+// return new Builder(type);
+// }
+//
+// /**
+// * New builder builder using this instance's settings.
+// *
+// * @return the builder
+// */
+// public Builder toBuilder() {
+// Builder builder = new Builder(this.type);
+// builder.enabled = this.enabled;
+// builder.type = this.type;
+// builder.ordinal = this.ordinal;
+// builder.name = this.name;
+// builder.sourceConfiguration = this.sourceConfiguration;
+// return builder;
+// }
+//
+// /**
+// * Is enabled boolean.
+// *
+// * @return the boolean
+// */
+// public boolean isEnabled() {
+// return enabled;
+// }
+//
+// /**
+// * Gets source configuration.
+// *
+// * @return the source configuration
+// */
+// public Map<String, String> getSourceConfiguration() {
+// return sourceConfiguration;
+// }
+//
+// /**
+// * Gets type.
+// *
+// * @return the type
+// */
+// public String getType() {
+// return type;
+// }
+//
+// /**
+// * Gets the current refresh interval, default is 0 meaning the property
+// * source is never refreshed.
+// *
+// * @return the refresh interval
+// */
+// public long getRefreshInterval() {
+// return refreshInterval;
+// }
+//
+// /**
+// * Gets name.
+// *
+// * @return the name
+// */
+// public String getName() {
+// return name;
+// }
+//
+// @Override
+// public String toString() {
+// return "PropertySourceConfig{" +
+// "enabled=" + enabled +
+// ", type='" + type + '\'' +
+// ", name='" + name + '\'' +
+// ", ordinal=" + ordinal +
+// ", sourceConfiguration=" + sourceConfiguration +
+// '}';
+// }
+//
+//
+// public <T> T create(Class<T> type)
+// throws ClassNotFoundException, IllegalAccessException,
+// InstantiationException {
+// return (T)Class.forName(this.getType()).newInstance();
+// }
+//
+//
+// /**
+// * {@code PropertySourceConfig} builder static inner class.
+// */
+// public static final class Builder {
+// private boolean enabled;
+// private String type;
+// private String name;
+// private Integer ordinal;
+// private long refreshInterval;
+// private Map<String, String> sourceConfiguration;
+//
+// private Builder(String type) {
+// this.type = Objects.requireNonNull(type);
+// if(type.trim().isEmpty()){
+// throw new IllegalArgumentException("Type is empty.");
+// }
+// }
+//
+// /**
+// * Sets the {@code refreshInterval} and returns a reference to this Builder so that the methods can be chained together.
+// *
+// * @param val the {@code refreshInterval} to set
+// * @return a reference to this Builder
+// */
+// public Builder withRefreshInterval(long val) {
+// refreshInterval = val;
+// return this;
+// }
+//
+// /**
+// * Sets the {@code ordinal} and returns a reference to this Builder so that the methods can be chained together.
+// *
+// * @param val the {@code ordinal} to set
+// * @return a reference to this Builder
+// */
+// public Builder withOrdinal(Integer val) {
+// ordinal = val;
+// return this;
+// }
+//
+// /**
+// * Sets the {@code enabled} and returns a reference to this Builder so that the methods can be chained together.
+// *
+// * @param val the {@code enabled} to set
+// * @return a reference to this Builder
+// */
+// public Builder withEnabled(boolean val) {
+// enabled = val;
+// return this;
+// }
+//
+// /**
+// * Sets the {@code type} and returns a reference to this Builder so that the methods can be chained together.
+// *
+// * @param val the {@code type} to set
+// * @return a reference to this Builder
+// */
+// public Builder withType(String val) {
+// type = val;
+// return this;
+// }
+//
+// /**
+// * Sets the {@code name} and returns a reference to this Builder so that the methods can be chained together.
+// *
+// * @param val the {@code name} to set
+// * @return a reference to this Builder
+// */
+// public Builder withName(String val) {
+// name = val;
+// return this;
+// }
+//
+// /**
+// * Sets the {@code sourceConfiguration} and returns a reference to this Builder so that the methods can be chained together.
+// *
+// * @param val the {@code sourceConfiguration} to set
+// * @return a reference to this Builder
+// */
+// public Builder withSourceConfiguration(Map<String, String> val) {
+// sourceConfiguration = val;
+// return this;
+// }
+//
+// /**
+// * Returns a {@code PropertySourceConfig} built from the parameters previously set.
+// *
+// * @return a {@code PropertySourceConfig} built with parameters of this {@code PropertySourceConfig.Builder}
+// */
+// public SourceConfig build() {
+// return new SourceConfig(this);
+// }
+// }
+//}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..ae4bf24
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java
@@ -0,0 +1,47 @@
+/*
+ * 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.factories;
+
+import org.apache.tamaya.metamodel.spi.ItemFactory;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spisupport.CLIPropertySource;
+import org.apache.tamaya.spisupport.EnvironmentPropertySource;
+
+import java.util.Map;
+
+/**
+ * Factory for configuring CLI argument based property sources.
+ */
+public final class CLIArgumentsFactory implements ItemFactory<PropertySource>{
+ @Override
+ public String getName() {
+ return "CLI";
+ }
+
+ @Override
+ public PropertySource create(Map<String,String> parameters) {
+ return new CLIPropertySource();
+ }
+
+ @Override
+ public Class<? extends PropertySource> getType() {
+ return PropertySource.class;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactory.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactory.java
new file mode 100644
index 0000000..f6c9909
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactory.java
@@ -0,0 +1,46 @@
+/*
+ * 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.factories;
+
+import org.apache.tamaya.metamodel.spi.ItemFactory;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spisupport.EnvironmentPropertySource;
+
+import java.util.Map;
+
+/**
+ * Factory for configuring environment properties based property sources.
+ */
+public final class EnvPropertiesFactory implements ItemFactory<PropertySource>{
+ @Override
+ public String getName() {
+ return "env-properties";
+ }
+
+ @Override
+ public PropertySource create(Map<String,String> parameters) {
+ return new EnvironmentPropertySource();
+ }
+
+ @Override
+ public Class<? extends PropertySource> getType() {
+ return PropertySource.class;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactory.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..d3961d4
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactory.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tamaya.metamodel.internal.factories;
+
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.ConfigurationFormats;
+import org.apache.tamaya.format.MappedConfigurationDataPropertySource;
+import org.apache.tamaya.metamodel.spi.ItemFactory;
+import org.apache.tamaya.resource.ConfigResources;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spisupport.PropertiesResourcePropertySource;
+import org.apache.tamaya.spisupport.SimplePropertySource;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Factory for configuring file based property sources.
+ */
+public final class FilePropertySourceFactory extends ResourcePropertySourceFactory{
+
+ private static final Logger LOG = Logger.getLogger(FilePropertySourceFactory.class.getName());
+
+ @Override
+ public String getName() {
+ return "file";
+ }
+
+ @Override
+ protected String example() {
+ return "<source type=\""+getName()+"\">\n" +
+ " <param name=\"location\">c:/temp/config.xml</param>\n" +
+ " <param name=\"formats\">xml-properties</param>\n" +
+ "</source>\n";
+ }
+
+ @Override
+ protected URL createResource(String location) {
+ try {
+ Path path = Paths.get(location);
+ if(!path.toFile().exists()){
+ LOG.info("Cannot read resource '" + location + "': no such file.");
+ }else if(!path.toFile().canRead()){
+ LOG.info("Cannot read resource '" + location + "': not readable.");
+ }
+ return path.toUri().toURL();
+ } catch (MalformedURLException e) {
+ LOG.warning("Invalid file '" + location + "'.");
+ return null;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactory.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..a36fd7f
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactory.java
@@ -0,0 +1,64 @@
+/*
+ * 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.factories;
+
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.ConfigurationFormats;
+import org.apache.tamaya.format.MappedConfigurationDataPropertySource;
+import org.apache.tamaya.metamodel.spi.ItemFactory;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spisupport.PropertiesResourcePropertySource;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Factory for configuring resource based property sources.
+ */
+public class ResourcePropertySourceFactory extends URLPropertySourceFactory{
+
+ private static final Logger LOG = Logger.getLogger(ResourcePropertySourceFactory.class.getName());
+
+ @Override
+ public String getName() {
+ return "classpath";
+ }
+
+
+ protected String example() {
+ return "<source type=\""+getName()+"\">\n" +
+ " <param name=\"location\">/META-INF/config.xml</param>\n" +
+ " <param name=\"formats\">xml-properties</param>\n" +
+ "</source>\n";
+ }
+
+ protected URL createResource(String location) {
+ try {
+ return getClass().getClassLoader().getResource(location);
+ } catch (Exception e) {
+ LOG.warning("Invalid resource '" + location + "'.");
+ return null;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactory.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..77f22d4
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactory.java
@@ -0,0 +1,115 @@
+/*
+ * 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.factories;
+
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.ConfigurationFormats;
+import org.apache.tamaya.format.MappedConfigurationDataPropertySource;
+import org.apache.tamaya.metamodel.spi.ItemFactory;
+import org.apache.tamaya.resource.ConfigResources;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.net.URL;
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Factory for configuring resource based property sources.
+ */
+public class ResourcePropertySourceProviderFactory implements ItemFactory<PropertySourceProvider>{
+
+ private static final Logger LOG = Logger.getLogger(ResourcePropertySourceProviderFactory.class.getName());
+
+ @Override
+ public String getName() {
+ return "resource";
+ }
+
+ @Override
+ public PropertySourceProvider create(Map<String,String> parameters) {
+ String location = parameters.get("location");
+ if(location==null){
+ LOG.warning("Cannot read 'location' from " + parameters + ", example: " + example());
+ return null;
+ }
+ Collection<URL> resources = createResources(location);
+ List<PropertySource> propertySources = new ArrayList<>();
+ if(resources!=null) {
+ String[] formats = getFormats(parameters);
+ for(URL resource:resources) {
+ ConfigurationData data;
+ try {
+ if (formats.length == 0) {
+ data = ConfigurationFormats.readConfigurationData(resource);
+ } else {
+ data = ConfigurationFormats.readConfigurationData(resource,
+ ConfigurationFormats.getFormats(formats));
+ }
+ propertySources.add(new MappedConfigurationDataPropertySource(data));
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Failed to read property source from resource: " + location, e);
+ }
+ }
+ }
+ final List<PropertySource> finalPropertySources = Collections.unmodifiableList(propertySources);
+ return new PropertySourceProvider() {
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ return finalPropertySources;
+ }
+ };
+ }
+
+ @Override
+ public Class<? extends PropertySourceProvider> getType() {
+ return PropertySourceProvider.class;
+ }
+
+ protected String[] getFormats(Map<String, String> parameters) {
+ String val = parameters.get("formats");
+ if(val==null){
+ return new String[0];
+ }
+ String[] formats = val.split(",");
+ for(int i=0;i<formats.length;i++){
+ formats[i] = formats[i].trim();
+ }
+ return formats;
+ }
+
+ protected String example() {
+ return "<source-provider type=\""+getName()+"\">\n" +
+ " <param name=\"location\">/META-INF/**/config.xml</param>\n" +
+ " <param name=\"formats\">xml-properties</param>\n" +
+ "</source-provider>\n";
+ }
+
+ protected Collection<URL> createResources(String location) {
+ try {
+ return ConfigResources.getResourceResolver().getResources(location.split(":"));
+ } catch (Exception e) {
+ LOG.warning("Invalid resource expression '" + location + "'.");
+ return null;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactory.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactory.java
new file mode 100644
index 0000000..aec4837
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactory.java
@@ -0,0 +1,46 @@
+/*
+ * 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.factories;
+
+import org.apache.tamaya.metamodel.spi.ItemFactory;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spisupport.SystemPropertySource;
+
+import java.util.Map;
+
+/**
+ * Factory for configuring system properties based property sources.
+ */
+public final class SysPropertiesFactory implements ItemFactory<PropertySource>{
+ @Override
+ public String getName() {
+ return "sys-properties";
+ }
+
+ @Override
+ public PropertySource create(Map<String,String> parameters) {
+ return new SystemPropertySource();
+ }
+
+ @Override
+ public Class<? extends PropertySource> getType() {
+ return PropertySource.class;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactory.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..342eebb
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactory.java
@@ -0,0 +1,152 @@
+/*
+ * 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.factories;
+
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.ConfigurationFormats;
+import org.apache.tamaya.format.MappedConfigurationDataPropertySource;
+import org.apache.tamaya.functions.Supplier;
+import org.apache.tamaya.metamodel.internal.ComponentConfigurator;
+import org.apache.tamaya.metamodel.spi.ItemFactory;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spisupport.PropertiesResourcePropertySource;
+
+import javax.security.auth.RefreshFailedException;
+import javax.security.auth.Refreshable;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Factory for configuring resource based property sources.
+ */
+public class URLPropertySourceFactory implements ItemFactory<PropertySource>{
+
+ private static final Logger LOG = Logger.getLogger(FilePropertySourceFactory.class.getName());
+
+ @Override
+ public String getName() {
+ return "url";
+ }
+
+ @Override
+ public PropertySource create(Map<String,String> parameters) {
+ String location = parameters.get("location");
+ if(location==null){
+ LOG.warning("Cannot read 'location' from " + parameters + ", example: " + example());
+ return null;
+ }
+ URL resource = createResource(location);
+ if(resource!=null) {
+ String[] formats = getFormats(parameters);
+ String name = resource.toString();
+ RefreshablePropertySource ps = new RefreshablePropertySource(name, new LazyDataSupplier(resource, formats));
+ ComponentConfigurator.configure(ps, parameters);
+ return ps;
+ }
+ return null;
+ }
+
+ protected String example() {
+ return "<source type=\""+getName()+"\">\n" +
+ " <param name=\"location\">http://127.0.0.1:1110/config.xml</param>\n" +
+ " <param name=\"formats\">xml-properties</param>\n" +
+ "</source>\n";
+ }
+
+ protected URL createResource(String location) {
+ try {
+ return new URL(location);
+ } catch (MalformedURLException e) {
+ LOG.warning("Invalid url '" + location + "'.");
+ return null;
+ }
+ }
+
+ protected String[] getFormats(Map<String, String> parameters) {
+ String val = parameters.get("formats");
+ if(val==null){
+ return new String[0];
+ }
+ String[] formats = val.split(",");
+ for(int i=0;i<formats.length;i++){
+ formats[i] = formats[i].trim();
+ }
+ return formats;
+ }
+
+ @Override
+ public Class<? extends PropertySource> getType() {
+ return PropertySource.class;
+ }
+
+ private static final class LazyDataSupplier implements Supplier<ConfigurationData> {
+
+ private String[] formats;
+ private URL resource;
+
+ public LazyDataSupplier(URL resource, String[] formats) {
+ this.formats = Objects.requireNonNull(formats);
+ this.resource = Objects.requireNonNull(resource);
+ }
+
+ @Override
+ public ConfigurationData get() {
+ ConfigurationData data;
+ try {
+ if (formats.length == 0) {
+ data = ConfigurationFormats.readConfigurationData(resource);
+ } else {
+ data = ConfigurationFormats.readConfigurationData(resource,
+ ConfigurationFormats.getFormats(formats));
+ }
+ return data;
+ } catch (Exception e) {
+ LOG.log(Level.INFO, "Failed to read property source from resource: " + resource, e);
+ return null;
+ }
+ }
+ }
+
+ private static final class RefreshablePropertySource extends MappedConfigurationDataPropertySource
+ implements Refreshable{
+
+ public RefreshablePropertySource(String name, Supplier<ConfigurationData> dataSupplier) {
+ super(name, dataSupplier);
+ }
+
+ public RefreshablePropertySource(String name, int defaultOrdinal, Supplier<ConfigurationData> dataSupplier) {
+ super(name, dataSupplier);
+ }
+
+ @Override
+ public boolean isCurrent() {
+ return false;
+ }
+
+ @Override
+ public void refresh() throws RefreshFailedException {
+ super.load();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/afc19d0e/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/ItemFactory.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/ItemFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/ItemFactory.java
new file mode 100644
index 0000000..1cfb8b9
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/spi/ItemFactory.java
@@ -0,0 +1,51 @@
+/*
+ * 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.spi;
+
+import java.util.Map;
+
+/**
+ * Factory for items that are configurable using meta-configuration.
+ * This allows easy registration using the name, instead of the fully qualified
+ * class name.
+ */
+public interface ItemFactory<T> {
+
+ /**
+ * Get the factory name.
+ * @return the factory name, not null.
+ */
+ String getName();
+
+ /**
+ * Create a new instance.
+ * @param parameters the parameters for configuring the instance.
+ * @return the new instance, not null.
+ */
+ T create(Map<String,String> parameters);
+
+ /**
+ * Get the target type created by this factory. This can be used to
+ * assign the factory to an acording item base type, e.g. a PropertySource,
+ * PropertySourceProvider, PropertyFilter etc.
+ * @return the target type, not null.
+ */
+ Class<? extends T> getType();
+
+}