You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2014/12/24 02:12:11 UTC
[1/6] incubator-tamaya git commit: TAMAYA-19: - Moved out much of
unused/experimental code. - Reduced API (removing package private singletons)
- Aligned PropertySource with Deltaspike (mostly). - Moved Environment model
to separate metamodel module.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 22d2d1ad8 -> a3c10d6ed
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
new file mode 100644
index 0000000..6f05466
--- /dev/null
+++ b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
@@ -0,0 +1,108 @@
+/*
+ * 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.environment.internal;
+
+import org.apache.tamaya.core.config.ConfigurationFormats;
+import org.apache.tamaya.core.resource.Resource;
+import org.apache.tamaya.metamodel.environment.EnvironmentBuilder;
+import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
+import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.resource.ResourceLoader;
+
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class implements a {@link EnvironmentProvider} that tries
+ * to read configuration for an ear deployment located under {@code META-INF/env/ear.properties,
+ * META-INF/env/ear.xml or META-INF/env/ear.ini}. The environment id hereby is defined by a
+ * configuration entry named {@code org.apache.tamaya.core.env.earId}.
+ *
+ * Only if such a configuration with such an {@code earId} is found an {@link org.apache.tamaya.metamodel.environment.Environment}
+ * is created and attached to the corresponding ear classloader.
+ */
+public class ClassLoaderDependentEarEnvironmentProvider implements EnvironmentProvider {
+
+ private static final Logger LOG = Logger.getLogger(ClassLoaderDependentEarEnvironmentProvider.class.getName());
+
+// private static final String EARID_PROP = "environment.earId";
+
+ private Map<ClassLoader, Map<String,String>> environments = new ConcurrentHashMap<>();
+ private Map<ClassLoader, Boolean> environmentAvailable = new ConcurrentHashMap<>();
+
+ @Override
+ public boolean isActive() {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if(cl==null){
+ return false;
+ }
+ Boolean available = this.environmentAvailable.get(cl);
+ if(available!=null && !available){
+ return false;
+ }
+ List<Resource> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
+ "classpath:META-INF/env/ear.properties", "classpath:META-INF/env/ear.xml", "classpath:META-INF/env/ear.ini");
+ available = !propertyUris.isEmpty();
+ this.environmentAvailable.put(cl, available);
+ return available;
+ }
+
+ @Override
+ public Map<String,String> getEnvironmentData() {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if(cl==null){
+ return null;
+ }
+ Map<String,String> data = this.environments.get(cl);
+ if(data!=null){
+ return data;
+ }
+ List<Resource> resources = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
+ "classpath:META-INF/env/ear.properties", "classpath:META-INF/env/ear.xml", "classpath:META-INF/env/ear.ini");
+ data = new HashMap<>();
+ for(Resource resource:resources){
+ try{
+ ConfigurationFormat format = ConfigurationFormats.getFormat(resource);
+ Map<String,String> read = format.readConfiguration(resource);
+ data.putAll(read);
+ }
+ catch(Exception e){
+ LOG.log(Level.SEVERE, e, () -> "Error reading ear environment data fromMap " + resource);
+ }
+ }
+// String earId = data.getOrDefault(EARID_PROP, cl.toString());
+ String stageValue = data.get(EnvironmentBuilder.STAGE_PROP);
+ if (stageValue != null) {
+ data.put(EnvironmentBuilder.STAGE_PROP,stageValue);
+ }
+ data.put("classloader.type", cl.getClass().getName());
+ data.put("classloader.info", cl.toString());
+ Set<Resource> resourceSet = new HashSet<>();
+ resourceSet.addAll(resources);
+ data.put("environment.sources", resourceSet.toString());
+ data = Collections.unmodifiableMap(data);
+ this.environments.put(cl, data);
+ return data;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/InitialEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/InitialEnvironmentProvider.java b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/InitialEnvironmentProvider.java
new file mode 100644
index 0000000..9321539
--- /dev/null
+++ b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/InitialEnvironmentProvider.java
@@ -0,0 +1,74 @@
+/*
+ * 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.environment.internal;
+
+import java.net.InetAddress;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.TimeZone;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tamaya.core.env.ConfiguredSystemProperties;
+import org.apache.tamaya.metamodel.environment.EnvironmentBuilder;
+import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
+
+/**
+ * Default {@link org.apache.tamaya.metamodel.environment.Environment}.
+ */
+public final class InitialEnvironmentProvider implements EnvironmentProvider{
+
+ private Map<String,String> environmentData = new HashMap<>();
+
+ public InitialEnvironmentProvider() {
+ Properties props = System.getProperties();
+ if(props instanceof ConfiguredSystemProperties){
+ props = ((ConfiguredSystemProperties)props).getInitialProperties();
+ }
+ String stageValue = props.getProperty(EnvironmentBuilder.STAGE_PROP);
+ environmentData.put(EnvironmentBuilder.STAGE_PROP, stageValue);
+ environmentData.put("timezone", TimeZone.getDefault().getID());
+ environmentData.put("locale", Locale.getDefault().toString());
+ try {
+ environmentData.put("host", InetAddress.getLocalHost().toString());
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName()).log(Level.WARNING, e, () -> "Failed to evaluate hostname.");
+ }
+ // Copy env properties....
+ for (Entry<String, String> en : System.getenv().entrySet()) {
+ environmentData.put(en.getKey(), en.getValue());
+ }
+ environmentData = Collections.unmodifiableMap(environmentData);
+ }
+
+ @Override
+ public boolean isActive(){
+ return true;
+ }
+
+ @Override
+ public Map<String,String> getEnvironmentData() {
+ return environmentData;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SingleEnvironmentManager.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SingleEnvironmentManager.java b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SingleEnvironmentManager.java
new file mode 100644
index 0000000..cbf177d
--- /dev/null
+++ b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SingleEnvironmentManager.java
@@ -0,0 +1,70 @@
+/*
+ * 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.environment.internal;
+
+
+import org.apache.tamaya.metamodel.environment.Environment;
+import org.apache.tamaya.metamodel.environment.EnvironmentBuilder;
+import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
+import org.apache.tamaya.metamodel.environment.spi.EnvironmentSpi;
+import org.apache.tamaya.spi.ServiceContext;
+
+import java.util.*;
+
+/**
+ * Service for accessing {@link org.apache.tamaya.metamodel.environment.Environment}. Environments are used to
+ * access/determine configurations.<br/>
+ * <h3>Implementation PropertyMapSpec</h3> This class is
+ * <ul>
+ * <li>thread safe,
+ * <li>and behaves contextual.
+ * </ul>
+ */
+public class SingleEnvironmentManager implements EnvironmentSpi {
+
+ private final List<EnvironmentProvider> environmentProviders = loadEnvironmentProviders();
+ private Environment rootEnvironment = getCurrentEnvironment();
+
+ private List<EnvironmentProvider> loadEnvironmentProviders() {
+ List<EnvironmentProvider> providerList = new ArrayList<>();
+ for(EnvironmentProvider prov: ServiceContext.getInstance().getServices(EnvironmentProvider.class)){
+ providerList.add(prov);
+ }
+ return providerList;
+ }
+
+ @Override
+ public Environment getCurrentEnvironment(){
+ EnvironmentBuilder b = EnvironmentBuilder.of();
+ for(EnvironmentProvider prov: environmentProviders){
+ if(prov.isActive()){
+ if(prov.isActive()){
+ b.setAll(prov.getEnvironmentData());
+ }
+ }
+ }
+ return b.build();
+ }
+
+ @Override
+ public Environment getRootEnvironment(){
+ return rootEnvironment;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SystemClassLoaderEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SystemClassLoaderEnvironmentProvider.java b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SystemClassLoaderEnvironmentProvider.java
new file mode 100644
index 0000000..d0def60
--- /dev/null
+++ b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SystemClassLoaderEnvironmentProvider.java
@@ -0,0 +1,74 @@
+/*
+ * 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.environment.internal;
+
+import org.apache.tamaya.core.config.ConfigurationFormats;
+import org.apache.tamaya.core.resource.Resource;
+import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
+import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.resource.ResourceLoader;
+
+
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * System environment provider (loaded only once using the system class loader) that loads additional environment properties fromMap the classpath evaluating
+ * {@code META-INF/env/system.properties, META-INF/env/system.xml and META-INF/env/system.ini}.
+ */
+public class SystemClassLoaderEnvironmentProvider implements EnvironmentProvider {
+
+ private static final Logger LOG = Logger.getLogger(SystemClassLoaderEnvironmentProvider.class.getName());
+
+ private Map<String,String> data = new HashMap<>();
+
+
+ public SystemClassLoaderEnvironmentProvider(){
+ List<Resource> propertyResources = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(ClassLoader.getSystemClassLoader(),
+ "classpath:META-INF/env/system.properties", "classpath:META-INF/env/system.xml", "classpath:META-INF/env/system.ini");
+ for(Resource resource:propertyResources){
+ try{
+ ConfigurationFormat format = ConfigurationFormats.getFormat(resource);
+ Map<String,String> data = format.readConfiguration(resource);
+ data.putAll(data);
+ }
+ catch(Exception e){
+ LOG.log(Level.INFO, e, () -> "Could not read environment data from " + resource);
+ }
+ }
+ data.put("classloader.type", ClassLoader.getSystemClassLoader().getClass().getName());
+ data.put("classloader.info", ClassLoader.getSystemClassLoader().toString());
+ Set<Resource> resourceSet = new HashSet<>();
+ resourceSet.addAll(propertyResources);
+ data.put("environment.system.sources", resourceSet.toString());
+ this.data = Collections.unmodifiableMap(data);
+ }
+ @Override
+ public boolean isActive() {
+ return true;
+ }
+
+ @Override
+ public Map<String,String> getEnvironmentData() {
+ return data;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/spi/EnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/spi/EnvironmentProvider.java b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/spi/EnvironmentProvider.java
new file mode 100644
index 0000000..ef4ff43
--- /dev/null
+++ b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/spi/EnvironmentProvider.java
@@ -0,0 +1,44 @@
+/*
+ * 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.environment.spi;
+
+import java.util.Map;
+
+/**
+ * SPI for components that define a concrete type current {@link org.apache.tamaya.metamodel.environment.Environment}.
+ * The chain current environment config determine the current {@link org.apache.tamaya.metamodel.environment.Environment} active
+ * and its parent instances.
+ * Created by Anatole on 14.10.2014.
+ */
+public interface EnvironmentProvider {
+
+ /**
+ * Evaluates if an environment is currently active.
+ * @return
+ */
+ boolean isActive();
+
+ /**
+ * Returns the properties to be added to the environment.
+ * @return the properties, or an empty map if no properties are to be added (or the provider is not active for the
+ * current runtime state).
+ */
+ Map<String,String> getEnvironmentData();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/spi/EnvironmentSpi.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/spi/EnvironmentSpi.java b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/spi/EnvironmentSpi.java
new file mode 100644
index 0000000..dbf8f65
--- /dev/null
+++ b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/spi/EnvironmentSpi.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.metamodel.environment.spi;
+
+
+import org.apache.tamaya.metamodel.environment.Environment;
+
+/**
+ * Service for accessing {@link org.apache.tamaya.metamodel.environment.Environment}. Environments are used to
+ * access/determine configurations.<br/>
+ * <h3>Implementation PropertyMapSpec</h3> This class is
+ * <ul>
+ * <li>thread safe,
+ * <li>and behaves contextual.
+ * </ul>
+ */
+public interface EnvironmentSpi {
+
+ /**
+ * Get the current environment current the given environment type.
+ * @return the corresponding environment, never null.
+ * @throws IllegalArgumentException if not such type is present or active.
+ */
+ Environment getCurrentEnvironment();
+
+ /**
+ * Get the current environment current the given environment type.
+ * @return the corresponding environment, never null.
+ * @throws IllegalArgumentException if not such type is present or active.
+ */
+ Environment getRootEnvironment();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/environment/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.EnvironmentProvider
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.EnvironmentProvider b/modules/metamodels/environment/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.EnvironmentProvider
new file mode 100644
index 0000000..3592434
--- /dev/null
+++ b/modules/metamodels/environment/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.EnvironmentProvider
@@ -0,0 +1,22 @@
+#
+# 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.core.internal.env.InitialEnvironmentProvider
+org.apache.tamaya.core.internal.env.SystemClassLoaderEnvironmentProvider
+org.apache.tamaya.core.internal.env.ClassLoaderDependentEarEnvironmentProvider
+org.apache.tamaya.core.internal.env.ClassLoaderDependentApplicationEnvironmentProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentSpi
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentSpi b/modules/metamodels/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentSpi
new file mode 100644
index 0000000..4a5b828
--- /dev/null
+++ b/modules/metamodels/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentSpi
@@ -0,0 +1,19 @@
+#
+# 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.environment.TestEnvironmentManagerSingleton
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java b/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java
new file mode 100644
index 0000000..5abdd8e
--- /dev/null
+++ b/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.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.environment;
+
+import org.apache.tamaya.Environment;
+import org.junit.Test;
+
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for basic {@link org.apache.tamaya.EnvironmentManager} functionality.
+ * Created by Anatole on 17.10.2014.
+ */
+public class EnvironmentManagerTest {
+
+ @Test
+ public void testGetEnvironment(){
+ Environment env = Environment.current();
+ assertNotNull(env);
+ Environment env2 = Environment.current();
+ assertNotNull(env2);
+ assertFalse("Current Environments requested in same context are not the same!", env==env2);
+ }
+
+ @Test
+ public void testGetRootEnvironment(){
+ Environment env = Environment.root();
+ assertNotNull(env);
+ Environment env2 = Environment.root();
+ assertNotNull(env2);
+ assertTrue("Root Environments requested in same context are not the same!", env==env2);
+ }
+
+ @Test
+ public void testRootIsNotCurrentEnvironment(){
+ Environment env1 = Environment.root();
+ Environment env2 = Environment.current();
+ assertNotNull(env1);
+ assertNotNull(env2);
+ // within this test environment these are always the same
+ assertEquals(env1, env2);
+ }
+
+ @Test
+ public void testEnvironmentOverride(){
+ assertEquals(Environment.root().get("user.country").get(),System.getProperty("user.country"));
+ assertEquals(Environment.current().get("user.country").get(), System.getProperty("user.country"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentManagerSingleton.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentManagerSingleton.java b/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentManagerSingleton.java
new file mode 100644
index 0000000..83a6056
--- /dev/null
+++ b/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentManagerSingleton.java
@@ -0,0 +1,37 @@
+/*
+ * 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.environment;
+
+import org.apache.tamaya.metamodel.environment.spi.EnvironmentSpi;
+
+/**
+ * Created by Anatole on 12.09.2014.
+ */
+public class TestEnvironmentManagerSingleton implements EnvironmentSpi {
+ @Override
+ public Environment getCurrentEnvironment(){
+ return null;
+ }
+
+ @Override
+ public Environment getRootEnvironment(){
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.java b/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.java
new file mode 100644
index 0000000..7524a80
--- /dev/null
+++ b/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.java
@@ -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.
+ */
+package org.apache.tamaya.metamodel.environment;
+
+import org.apache.tamaya.core.spi.EnvironmentProvider;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Environment provider used by some tests.
+ */
+public class TestEnvironmentProvider implements EnvironmentProvider {
+ private Map<String, String> data = new HashMap<>();
+
+ public TestEnvironmentProvider(){
+ data.put("user.country", System.getProperty("user.country"));
+ data.put("java.version", System.getProperty("java.version"));
+ data = Collections.unmodifiableMap(data);
+ }
+
+ @Override
+ public boolean isActive() {
+ return true;
+ }
+
+ @Override
+ public Map<String, String> getEnvironmentData() {
+ return data;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/pom.xml
----------------------------------------------------------------------
diff --git a/modules/metamodels/pom.xml b/modules/metamodels/pom.xml
index 23e2339..74b338f 100644
--- a/modules/metamodels/pom.xml
+++ b/modules/metamodels/pom.xml
@@ -40,6 +40,7 @@ under the License.
<modules>
<module>simple</module>
+ <module>environment</module>
</modules>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/pom.xml
----------------------------------------------------------------------
diff --git a/modules/pom.xml b/modules/pom.xml
index 695dc59..21b583d 100644
--- a/modules/pom.xml
+++ b/modules/pom.xml
@@ -54,6 +54,7 @@ under the License.
<modules>
<module>metamodels</module>
<module>integration</module>
+ <module>environment</module>
</modules>
</project>
[6/6] incubator-tamaya git commit: TAMAYA-19: - Moved out much of
unused/experimental code. - Reduced API (removing package private singletons)
- Aligned PropertySource with Deltaspike (mostly). - Moved Environment model
to separate metamodel module.
Posted by an...@apache.org.
TAMAYA-19:
- Moved out much of unused/experimental code.
- Reduced API (removing package private singletons)
- Aligned PropertySource with Deltaspike (mostly).
- Moved Environment model to separate metamodel module.
TAMAYA 36:
- Enabled direct mapped properties, including noconfig annotation. tbd further.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/a3c10d6e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/a3c10d6e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/a3c10d6e
Branch: refs/heads/master
Commit: a3c10d6edc3af9064483db50f23894231301d76e
Parents: 22d2d1a
Author: anatole <an...@apache.org>
Authored: Wed Dec 24 02:11:59 2014 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Dec 24 02:12:01 2014 +0100
----------------------------------------------------------------------
api/src/main/java/org/apache/tamaya/Codec.java | 10 +-
api/src/main/java/org/apache/tamaya/Codecs.java | 83 -----
.../java/org/apache/tamaya/ConfigChangeSet.java | 13 +-
.../apache/tamaya/ConfigChangeSetBuilder.java | 48 +--
.../java/org/apache/tamaya/Configuration.java | 119 +------
.../org/apache/tamaya/ConfigurationManager.java | 139 --------
.../java/org/apache/tamaya/ConfiguredValue.java | 261 ++++++++++++++
.../java/org/apache/tamaya/Environment.java | 83 -----
.../org/apache/tamaya/EnvironmentManager.java | 53 ---
.../java/org/apache/tamaya/PropertySource.java | 114 +++---
.../org/apache/tamaya/annotation/NoConfig.java | 32 ++
.../java/org/apache/tamaya/spi/CodecSpi.java | 89 +++++
.../apache/tamaya/spi/CodecsSingletonSpi.java | 89 -----
.../spi/ConfigurationManagerSingletonSpi.java | 116 ------
.../org/apache/tamaya/spi/ConfigurationSpi.java | 116 ++++++
.../spi/EnvironmentManagerSingletonSpi.java | 49 ---
.../tamaya/TestConfigServiceSingletonSpi.java | 9 +-
.../tamaya/TestEnvironmentManagerSingleton.java | 37 --
.../TestPropertyAdaptersSingletonSpi.java | 6 +-
.../services/org.apache.tamaya.spi.CodecSpi | 19 +
.../org.apache.tamaya.spi.CodecsSingletonSpi | 19 -
....tamaya.spi.ConfigurationManagerSingletonSpi | 19 -
.../org.apache.tamaya.spi.ConfigurationSpi | 19 +
...he.tamaya.spi.EnvironmentManagerSingletonSpi | 19 -
.../core/config/AbstractConfiguration.java | 18 +-
.../tamaya/core/config/ConfigFunctions.java | 104 +++++-
.../core/config/ConfigurationBuilder.java | 41 +--
.../tamaya/core/config/ConfigurationFormat.java | 111 ++++++
.../core/config/ConfigurationFormats.java | 91 -----
.../core/config/FreezedConfiguration.java | 17 +-
.../tamaya/core/config/MappedConfiguration.java | 6 +-
.../tamaya/core/env/BuildableEnvironment.java | 111 ------
.../core/env/ConfiguredSystemProperties.java | 353 -------------------
.../tamaya/core/env/EnvironmentBuilder.java | 99 ------
.../apache/tamaya/core/internal/MetaConfig.java | 5 +-
.../core/internal/config/DefaultCodecSpi.java | 169 +++++++++
...DefaultConfigurationManagerSingletonSpi.java | 136 -------
.../config/DefaultConfigurationSpi.java | 132 +++++++
.../core/internal/config/FileConfiguration.java | 16 +-
...DependentApplicationEnvironmentProvider.java | 101 ------
...ssLoaderDependentEarEnvironmentProvider.java | 108 ------
.../env/InitialEnvironmentProvider.java | 74 ----
.../internal/env/SingleEnvironmentManager.java | 70 ----
.../SystemClassLoaderEnvironmentProvider.java | 74 ----
.../DefaultConfigFormatsSingletonSpi.java | 78 ----
.../format/DefaultConfigurationFormatSpi.java | 78 ++++
.../tamaya/core/internal/format/IniFormat.java | 2 +-
.../core/internal/format/PropertiesFormat.java | 2 +-
.../internal/format/PropertiesXmlFormat.java | 2 +-
.../inject/ConfigChangeCallbackMethod.java | 6 +-
.../internal/inject/ConfigurationInjector.java | 6 -
.../core/internal/inject/ConfiguredMethod.java | 116 ------
.../internal/inject/ConfiguredSetterMethod.java | 136 +++++++
.../core/internal/inject/ConfiguredType.java | 154 ++++----
.../core/internal/inject/InjectionUtils.java | 80 ++++-
.../properties/DefaultCodecsSingletonSpi.java | 170 ---------
.../resources/DefaultPathResourceLoader.java | 81 -----
.../resources/DefaultResourceLoader.java | 81 +++++
.../AbstractClasspathAwarePropertySource.java | 9 +-
.../core/properties/AbstractPropertySource.java | 36 +-
.../properties/AggregatedPropertySource.java | 11 +-
.../properties/BuildablePropertySource.java | 22 +-
.../properties/ContextualPropertySource.java | 37 +-
.../properties/DelegatingPropertySource.java | 34 +-
.../properties/EnvironmentPropertySource.java | 4 +-
.../core/properties/FilteredPropertySource.java | 10 +-
.../core/properties/FreezedPropertySource.java | 38 +-
.../properties/IntersectingPropertySource.java | 24 +-
.../core/properties/MapBasedPropertySource.java | 14 +-
.../properties/PathBasedPropertySource.java | 17 +-
.../core/properties/PropertySourceBuilder.java | 256 +++++---------
.../core/properties/PropertySourceFactory.java | 133 ++++---
.../properties/ReplacingPropertySource.java | 31 +-
.../properties/SubtractingPropertySource.java | 11 +-
.../SystemPropertiesPropertySource.java | 19 +-
.../core/properties/URLBasedPropertySource.java | 20 +-
.../tamaya/core/resource/ResourceLoader.java | 8 +-
.../tamaya/core/spi/AdapterProviderSpi.java | 36 --
.../tamaya/core/spi/CodecProviderSpi.java | 36 ++
.../tamaya/core/spi/ConfigurationFormat.java | 57 ---
.../tamaya/core/spi/ConfigurationFormatSpi.java | 61 ++++
.../spi/ConfigurationFormatsSingletonSpi.java | 60 ----
.../tamaya/core/spi/EnvironmentProvider.java | 46 ---
.../core/spi/ObjectConfiguratorService.java | 37 --
.../tamaya/core/spi/ObjectConfiguratorSpi.java | 37 ++
.../tamaya/core/spi/PropertyAdapterService.java | 128 +++----
.../resources/META-INF/java-config-1.0.0.xsd | 80 -----
.../src/main/resources/META-INF/java-config.xml | 33 --
.../resources/META-INF/meta-model.properties | 39 --
...pache.tamaya.core.config.ConfigurationFormat | 21 ++
...g.apache.tamaya.core.resource.ResourceLoader | 2 +-
...g.apache.tamaya.core.spi.ConfigurationFormat | 21 --
...pache.tamaya.core.spi.ConfigurationFormatSpi | 19 +
...ya.core.spi.ConfigurationFormatsSingletonSpi | 19 -
...g.apache.tamaya.core.spi.EnvironmentProvider | 22 --
.../services/org.apache.tamaya.spi.CodecSpi | 19 +
.../org.apache.tamaya.spi.CodecsSingletonSpi | 19 -
....tamaya.spi.ConfigurationManagerSingletonSpi | 19 -
.../org.apache.tamaya.spi.ConfigurationSpi | 19 +
...he.tamaya.spi.EnvironmentManagerSingletonSpi | 19 -
.../org.apache.tamaya.spi.StagesSingletonSpi | 19 -
...tionManagerSingletonSpiSingletonSpiTest.java | 35 +-
.../java/org/apache/tamaya/JavaOneDemo.java | 9 +-
.../config/ConfiguredSystemPropertiesTest.java | 94 +++++
.../core/config/EnvironmentManagerTest.java | 40 ---
.../env/ConfiguredSystemPropertiesTest.java | 46 ---
.../tamaya/core/env/EnvironmentManagerTest.java | 66 ----
.../internal/MutableTestConfigProvider.java | 8 +-
.../internal/TestEnvironmentProvider.java | 48 ---
.../annotations/AutoConfiguredClass.java | 91 +++++
.../samples/annotations/AutoConfiguredTest.java | 43 +++
.../simple/SimplePropertiesAndCLISample.java | 9 +-
.../apache/tamaya/ucs/UC1ReadProperties.java | 27 +-
.../apache/tamaya/ucs/UC2CombineProperties.java | 2 +-
...g.apache.tamaya.core.spi.EnvironmentProvider | 2 +-
core/src/test/resources/cfg/autoloaded.xml | 33 ++
core/src/test/resources/cfg/test.xml | 7 +
.../apache/tamaya/management/ManagedConfig.java | 2 +-
.../tamaya/management/ManagedConfigMBean.java | 2 +-
.../tamaya/management/ManagedEnvironment.java | 2 +-
.../management/ManagedEnvironmentMBean.java | 3 +-
modules/integration/pom.xml | 41 +--
.../se/ConfiguredSystemProperties.java | 353 +++++++++++++++++++
.../environment/BuildableEnvironment.java | 109 ++++++
.../metamodel/environment/Environment.java | 86 +++++
.../environment/EnvironmentBuilder.java | 97 +++++
...DependentApplicationEnvironmentProvider.java | 101 ++++++
...ssLoaderDependentEarEnvironmentProvider.java | 108 ++++++
.../internal/InitialEnvironmentProvider.java | 74 ++++
.../internal/SingleEnvironmentManager.java | 70 ++++
.../SystemClassLoaderEnvironmentProvider.java | 74 ++++
.../environment/spi/EnvironmentProvider.java | 44 +++
.../environment/spi/EnvironmentSpi.java | 49 +++
...g.apache.tamaya.core.spi.EnvironmentProvider | 22 ++
.../org.apache.tamaya.spi.EnvironmentSpi | 19 +
.../environment/EnvironmentManagerTest.java | 66 ++++
.../TestEnvironmentManagerSingleton.java | 37 ++
.../environment/TestEnvironmentProvider.java | 48 +++
modules/metamodels/pom.xml | 1 +
modules/pom.xml | 1 +
140 files changed, 3859 insertions(+), 4101 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/Codec.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/Codec.java b/api/src/main/java/org/apache/tamaya/Codec.java
index 4afaacb..90b9676 100644
--- a/api/src/main/java/org/apache/tamaya/Codec.java
+++ b/api/src/main/java/org/apache/tamaya/Codec.java
@@ -20,6 +20,8 @@ package org.apache.tamaya;
import org.apache.tamaya.annotation.WithCodec;
+import org.apache.tamaya.spi.CodecSpi;
+import org.apache.tamaya.spi.ServiceContext;
/**
* Interface for an codec that converts a configured String into something else and vice versa.
@@ -54,7 +56,7 @@ public interface Codec<T>{
* @return any adapter replaced with the new adapter, or null.
*/
public static <T> Codec<T> register(Class<T> targetType, Codec<T> adapter){
- return Codecs.register(targetType, adapter);
+ return ServiceContext.getInstance().getSingleton(CodecSpi.class).register(targetType, adapter);
}
/**
@@ -63,7 +65,7 @@ public interface Codec<T>{
* @return true, if the given target type is supported.
*/
public static boolean isTargetTypeSupported(Class<?> targetType){
- return Codecs.isTargetTypeSupported(targetType);
+ return ServiceContext.getInstance().getSingleton(CodecSpi.class).isTargetTypeSupported(targetType);
}
/**
@@ -74,7 +76,7 @@ public interface Codec<T>{
* @throws ConfigException if the target type is not supported.
*/
public static <T> Codec<T> getInstance(Class<T> targetType){
- return Codecs.getCodec(targetType);
+ return ServiceContext.getInstance().getSingleton(CodecSpi.class).getCodec(targetType, null);
}
/**
@@ -88,7 +90,7 @@ public interface Codec<T>{
* instantiated.
*/
public static <T> Codec<T> getInstance(Class<T> targetType, WithCodec annotation){
- return Codecs.getCodec(targetType, annotation);
+ return ServiceContext.getInstance().getSingleton(CodecSpi.class).getCodec(targetType, annotation);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/Codecs.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/Codecs.java b/api/src/main/java/org/apache/tamaya/Codecs.java
deleted file mode 100644
index 444c7c8..0000000
--- a/api/src/main/java/org/apache/tamaya/Codecs.java
+++ /dev/null
@@ -1,83 +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;
-
-import org.apache.tamaya.annotation.WithCodec;
-import org.apache.tamaya.spi.CodecsSingletonSpi;
-import org.apache.tamaya.spi.ServiceContext;
-
-/**
- * Singleton manager that provides {@link Codec} instance, usable for converting String
- * based configuration entries into any other target types and vice versa.
- * @see org.apache.tamaya.Codec
- */
-final class Codecs {
-
- /**
- * Orivate singleton constructor.
- */
- private Codecs(){}
-
- /**
- * Registers a new {@link Codec} for the given target type, hereby replacing any existing adapter for
- * this type.
- * @param targetType The target class, not null.
- * @param adapter The adapter, not null.
- * @param <T> The target type
- * @return any adapter replaced with the new adapter, or null.
- */
- public static <T> Codec<T> register(Class<T> targetType, Codec<T> adapter){
- return ServiceContext.getInstance().getSingleton(CodecsSingletonSpi.class).register(targetType, adapter);
- }
-
- /**
- * Checks if a {@link Codec} for given target type is available.
- * @param targetType the target type class
- * @return true, if the given target type is supported.
- */
- public static boolean isTargetTypeSupported(Class<?> targetType){
- return ServiceContext.getInstance().getSingleton(CodecsSingletonSpi.class).isTargetTypeSupported(targetType);
- }
-
- /**
- * Get an {@link Codec} converting to and from the given target type.
- * @param targetType the target type class
- * @param <T> the target type
- * @return the corresponding {@link Codec}, never null.
- * @throws ConfigException if the target type is not supported.
- */
- public static <T> Codec<T> getCodec(Class<T> targetType){
- return getCodec(targetType, null);
- }
-
- /**
- * Get an {@link Codec} converting to the given target type.
- * @param targetType the target type class
- * @param annotation the {@link org.apache.tamaya.annotation.WithCodec} annotation, or null. If the annotation is not null and
- * defines an overriding adapter, this instance is created and returned.
- * @param <T> the target type
- * @return the corresponding {@link Codec}, never null.
- * @throws ConfigException if the target type is not supported, or the overriding adapter cannot be
- * instantiated.
- */
- public static <T> Codec<T> getCodec(Class<T> targetType, WithCodec annotation){
- return ServiceContext.getInstance().getSingleton(CodecsSingletonSpi.class).getCodec(targetType, annotation);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/ConfigChangeSet.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/ConfigChangeSet.java b/api/src/main/java/org/apache/tamaya/ConfigChangeSet.java
index 4ff02ca..dda7701 100644
--- a/api/src/main/java/org/apache/tamaya/ConfigChangeSet.java
+++ b/api/src/main/java/org/apache/tamaya/ConfigChangeSet.java
@@ -19,6 +19,7 @@
package org.apache.tamaya;
import java.beans.PropertyChangeEvent;
+import java.io.Serializable;
import java.util.*;
/**
@@ -28,7 +29,9 @@ import java.util.*;
*
* Created by Anatole on 22.10.2014.
*/
-public final class ConfigChangeSet {
+public final class ConfigChangeSet implements Serializable{
+
+ private static final long serialVersionUID = 1l;
/** The base property provider/configuration. */
private PropertySource propertySource;
/** The base version, usable for optimistic locking. */
@@ -41,19 +44,17 @@ public final class ConfigChangeSet {
* @param propertyProvider The base property provider/configuration, not null.
* @return an empty ConfigChangeSet instance.
*/
- public static final ConfigChangeSet emptyChangeSet(PropertySource propertyProvider){
- return new ConfigChangeSet(propertyProvider, "<empty>", Collections.emptySet());
+ public static ConfigChangeSet emptyChangeSet(PropertySource propertyProvider){
+ return new ConfigChangeSet(propertyProvider, Collections.emptySet());
}
/**
* Constructor used by {@link ConfigChangeSetBuilder}.
* @param propertySource The base property provider/configuration, not null.
- * @param baseVersion The base version, usable for optimistic locking.
* @param changes The recorded changes, not null.
*/
- ConfigChangeSet(PropertySource propertySource, String baseVersion, Collection<PropertyChangeEvent> changes) {
+ ConfigChangeSet(PropertySource propertySource, Collection<PropertyChangeEvent> changes) {
this.propertySource = Objects.requireNonNull(propertySource);
- this.baseVersion = baseVersion;
changes.forEach((c) -> this.changes.put(c.getPropertyName(), c));
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/ConfigChangeSetBuilder.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/ConfigChangeSetBuilder.java b/api/src/main/java/org/apache/tamaya/ConfigChangeSetBuilder.java
index 9cd81b5..13d8fb3 100644
--- a/api/src/main/java/org/apache/tamaya/ConfigChangeSetBuilder.java
+++ b/api/src/main/java/org/apache/tamaya/ConfigChangeSetBuilder.java
@@ -43,10 +43,6 @@ public final class ConfigChangeSetBuilder {
*/
PropertySource source;
/**
- * The base version, if any. Used for optimistic version checking.
- */
- String baseVersion;
- /**
* Codesc provider, or null.
*/
Function<String, Codec> codecs;
@@ -55,13 +51,11 @@ public final class ConfigChangeSetBuilder {
* Constructor.
*
* @param source the underlying configuration/provider, not null.
- * @param baseVersion the base version, used for optimistic version checking.
* @param codecs function to provide customized codecs, when according values are changed, if not set the
* default codecs provided by {@link Codec#getInstance(Class)} are used.
*/
- private ConfigChangeSetBuilder(PropertySource source, String baseVersion, Function<String, Codec> codecs) {
+ private ConfigChangeSetBuilder(PropertySource source, Function<String, Codec> codecs) {
this.source = Objects.requireNonNull(source);
- this.baseVersion = baseVersion;
this.codecs = codecs;
}
@@ -72,7 +66,7 @@ public final class ConfigChangeSetBuilder {
* @return the builder for chaining.
*/
public static ConfigChangeSetBuilder of(PropertySource source) {
- return new ConfigChangeSetBuilder(source, Instant.now().toString(), null);
+ return new ConfigChangeSetBuilder(source, null);
}
/**
@@ -84,31 +78,7 @@ public final class ConfigChangeSetBuilder {
* @return the builder for chaining.
*/
public static ConfigChangeSetBuilder of(PropertySource source, Function<String, Codec> codecs) {
- return new ConfigChangeSetBuilder(source, Instant.now().toString(), codecs);
- }
-
- /**
- * Creates a new instance current this builder.
- *
- * @param source the underlying property provider/configuration, not null.
- * @param baseVersion the base version to be used.
- * @return the builder for chaining.
- */
- public static ConfigChangeSetBuilder of(PropertySource source, String baseVersion) {
- return new ConfigChangeSetBuilder(source, baseVersion, null);
- }
-
- /**
- * Creates a new instance current this builder.
- *
- * @param source the underlying property provider/configuration, not null.
- * @param baseVersion the base version to be used.
- * @param codecs function to provide customized codecs, when according values are changed, if not set the
- * default codecs provided by {@link Codec#getInstance(Class)} are used.
- * @return the builder for chaining.
- */
- public static ConfigChangeSetBuilder of(PropertySource source, String baseVersion, Function<String, Codec> codecs) {
- return new ConfigChangeSetBuilder(source, baseVersion, codecs);
+ return new ConfigChangeSetBuilder(source, codecs);
}
/**
@@ -118,7 +88,7 @@ public final class ConfigChangeSetBuilder {
* @return the builder for chaining.
*/
public static ConfigChangeSetBuilder of(Configuration configuration) {
- return new ConfigChangeSetBuilder(configuration, configuration.getVersion(), null);
+ return new ConfigChangeSetBuilder(configuration, null);
}
/**
@@ -130,7 +100,7 @@ public final class ConfigChangeSetBuilder {
* @return the builder for chaining.
*/
public static ConfigChangeSetBuilder of(Configuration configuration, Function<String, Codec> codecs) {
- return new ConfigChangeSetBuilder(configuration, configuration.getVersion(), codecs);
+ return new ConfigChangeSetBuilder(configuration, codecs);
}
@@ -389,7 +359,7 @@ public final class ConfigChangeSetBuilder {
*/
public ConfigChangeSetBuilder deleteAll() {
this.delta.clear();
- this.source.toMap().forEach((k, v) ->
+ this.source.getProperties().forEach((k, v) ->
this.delta.put(k, new PropertyChangeEvent(this.source, k, v, null)));
return this;
}
@@ -417,7 +387,7 @@ public final class ConfigChangeSetBuilder {
* @return the new change set, never null.
*/
public ConfigChangeSet build() {
- return new ConfigChangeSet(this.source, baseVersion, Collections.unmodifiableCollection(this.delta.values()));
+ return new ConfigChangeSet(this.source, Collections.unmodifiableCollection(this.delta.values()));
}
/**
@@ -430,7 +400,7 @@ public final class ConfigChangeSetBuilder {
*/
public static Collection<PropertyChangeEvent> compare(PropertySource map1, PropertySource map2) {
List<PropertyChangeEvent> changes = new ArrayList<>();
- for (Map.Entry<String, String> en : map1.toMap().entrySet()) {
+ for (Map.Entry<String, String> en : map1.getProperties().entrySet()) {
Optional<String> val = map2.get(en.getKey());
if (!val.isPresent()) {
changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
@@ -438,7 +408,7 @@ public final class ConfigChangeSetBuilder {
changes.add(new PropertyChangeEvent(map1, en.getKey(), val.get(), en.getValue()));
}
}
- for (Map.Entry<String, String> en : map2.toMap().entrySet()) {
+ for (Map.Entry<String, String> en : map2.getProperties().entrySet()) {
Optional<String> val = map1.get(en.getKey());
if (!val.isPresent()) {
changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/Configuration.java b/api/src/main/java/org/apache/tamaya/Configuration.java
index 775078b..543a515 100644
--- a/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -18,11 +18,12 @@
*/
package org.apache.tamaya;
+import org.apache.tamaya.spi.ConfigurationSpi;
+import org.apache.tamaya.spi.ServiceContext;
+
import java.util.*;
import java.util.function.Consumer;
-import java.util.function.Predicate;
import java.util.function.UnaryOperator;
-import java.util.stream.Collectors;
/**
* A configuration models a aggregated set current properties, identified by a unique key, but adds higher level access functions to
@@ -147,90 +148,7 @@ public interface Configuration extends PropertySource {
* type.
*/
default <T> Optional<T> get(String key, Class<T> type){
- return getAdapted(key, Codecs.getCodec(type));
- }
-
- /**
- * Return a set with all fully qualifies area names. This method should return the areas as accurate as possible,
- * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
- * does not support key iteration.
- *
- * @return s set with all areas, never {@code null}.
- */
- default Set<String> getAreas(){
- final Set<String> areas = new HashSet<>();
- this.keySet().forEach(s -> {
- int index = s.lastIndexOf('.');
- if(index > 0){
- areas.add(s.substring(0, index));
- }
- else{
- areas.add("<root>");
- }
- });
- return areas;
- }
-
- /**
- * Return a set with all fully qualified area names, containing the transitive closure also including all
- * subarea names, regardless if properties are accessible or not. This method should return the areas as accurate
- * as possible, but may not provide a complete set of areas that are finally accessible, especially when the
- * underlying storage does not support key iteration.
- *
- * @return s set with all transitive areas, never {@code null}.
- */
- default Set<String> getTransitiveAreas(){
- final Set<String> transitiveAreas = new HashSet<>();
- getAreas().forEach(s -> {
- int index = s.lastIndexOf('.');
- if (index < 0) {
- transitiveAreas.add("<root>");
- } else {
- while (index > 0) {
- s = s.substring(0, index);
- transitiveAreas.add(s);
- index = s.lastIndexOf('.');
- }
- }
- });
- return transitiveAreas;
- }
-
- /**
- * Return a set with all fully qualified area names, containing only the
- * areas that match the predicate and have properties attached. This method should return the areas as accurate as possible,
- * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
- * does not support key iteration.
- *
- * @param predicate A predicate to deternine, which areas should be returned, not {@code null}.
- * @return s set with all areas, never {@code null}.
- */
- default Set<String> getAreas(final Predicate<String> predicate){
- return getAreas().stream().filter(predicate).collect(Collectors.toCollection(TreeSet::new));
- }
-
- /**
- * Return a set with all fully qualified area names, containing the transitive closure also including all
- * subarea names, regardless if properties are accessible or not. This method should return the areas as accurate as possible,
- * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
- * does not support key iteration.
- *
- * @param predicate A predicate to deternine, which areas should be returned, not {@code null}.
- * @return s set with all transitive areas, never {@code null}.
- */
- default Set<String> getTransitiveAreas(Predicate<String> predicate){
- return getTransitiveAreas().stream().filter(predicate).collect(Collectors.toCollection(TreeSet::new));
- }
-
- /**
- * Allows to evaluate if an area exists. In case where the underlying storage implementation does not allow
- * querying the keys available, {@code false} should be returned.
- *
- * @param areaKey the configuration area (sub)path.
- * @return {@code true}, if such a node exists.
- */
- default boolean containsArea(String areaKey){
- return getAreas().contains(areaKey);
+ return getAdapted(key, Codec.getInstance(type));
}
/**
@@ -254,14 +172,6 @@ public interface Configuration extends PropertySource {
return query.query(this);
}
- /**
- * Field that allows property config to be versioned, meaning that each change on a provider requires this keys
- * to be incremented by one. This can be easily used to implement versioning (and optimistic locking)
- * in distributed (remote) usage scenarios.
- * @return the version current the current instance, or 'N/A'.
- */
- default String getVersion(){return "N/A";}
-
/**
* Allows to check if a configuration with a given name is defined.
@@ -269,11 +179,10 @@ public interface Configuration extends PropertySource {
* @param name the configuration's name, not null, not empty.
* @return true, if such a configuration is defined.
*/
- public static boolean isDefined(String name){
- return ConfigurationManager.isConfigurationDefined(name);
+ public static boolean isAvailable(String name){
+ return ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).isConfigurationAvailable(name);
}
-
/**
* Access a configuration by name.
*
@@ -282,7 +191,7 @@ public interface Configuration extends PropertySource {
* @throws ConfigException if no such configuration is defined.
*/
public static Configuration current(String name){
- return ConfigurationManager.getConfiguration(name);
+ return ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).getConfiguration(name);
}
/**
@@ -292,7 +201,7 @@ public interface Configuration extends PropertySource {
* @throws ConfigException if no such configuration is defined.
*/
public static Configuration current(){
- return ConfigurationManager.getConfiguration();
+ return ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).getConfiguration();
}
/**
@@ -307,7 +216,7 @@ public interface Configuration extends PropertySource {
* @throws ConfigException if the configuration could not be resolved.
*/
public static <T> T createTemplate(Class<T> type, Configuration... configurations){
- return ConfigurationManager.createTemplate(type, configurations);
+ return ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).createTemplate(type, configurations);
}
/**
@@ -322,7 +231,7 @@ public interface Configuration extends PropertySource {
* @throws ConfigException if the configuration could not be resolved.
*/
public static void configure(Object instance, Configuration... configurations){
- ConfigurationManager.configure(instance, configurations);
+ ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).configure(instance, configurations);
}
/**
@@ -335,7 +244,7 @@ public interface Configuration extends PropertySource {
* @return the evaluated config expression.
*/
public static String evaluateValue(String expression, Configuration... configurations){
- return ConfigurationManager.evaluateValue(expression, configurations);
+ return ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).evaluateValue(expression, configurations);
}
/**
@@ -343,7 +252,7 @@ public interface Configuration extends PropertySource {
* @param l the listener, not null.
*/
public static void addChangeListener(Consumer<ConfigChangeSet> l){
- ConfigurationManager.addChangeListener(l);
+ ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).addChangeListener(l);
}
/**
@@ -351,7 +260,7 @@ public interface Configuration extends PropertySource {
* @param l the listener, not null.
*/
public static void removeChangeListener(Consumer<ConfigChangeSet> l){
- ConfigurationManager.removeChangeListener(l);
+ ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).removeChangeListener(l);
}
/**
@@ -362,7 +271,7 @@ public interface Configuration extends PropertySource {
* @param configChange the change to be published, not null.
*/
public static void publishChange(ConfigChangeSet configChange){
- ConfigurationManager.publishChange(configChange);
+ ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).publishChange(configChange);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/ConfigurationManager.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/ConfigurationManager.java b/api/src/main/java/org/apache/tamaya/ConfigurationManager.java
deleted file mode 100644
index c753b22..0000000
--- a/api/src/main/java/org/apache/tamaya/ConfigurationManager.java
+++ /dev/null
@@ -1,139 +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;
-
-import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.spi.ConfigurationManagerSingletonSpi;
-
-import java.util.*;
-import java.util.function.Consumer;
-import java.util.function.Predicate;
-
-/**
- * Singleton accessor for accessing {@link Configuration} instances and
- * proxied configuration templates.
- */
-final class ConfigurationManager{
-
- /**
- * Private singleton constructor.
- */
- private ConfigurationManager(){
- }
-
- /**
- * Allows to check if a configuration with a given name is defined.
- *
- * @param name the configuration's name, not null, not empty.
- * @return true, if such a configuration is defined.
- */
- public static boolean isConfigurationDefined(String name){
- return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).isConfigurationDefined(name);
- }
-
-
- /**
- * Access a configuration by name.
- *
- * @param name the configuration's name, not null, not empty.
- * @return the corresponding Configuration instance, never null.
- * @throws ConfigException if no such configuration is defined.
- */
- public static Configuration getConfiguration(String name){
- return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).getConfiguration(name);
- }
-
- /**
- * Access a configuration.
- *
- * @return the corresponding Configuration instance, never null.
- * @throws ConfigException if no such configuration is defined.
- */
- public static Configuration getConfiguration(){
- return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).getConfiguration();
- }
-
- /**
- * Access a typed configuration, based on the default configuration.
- *
- * @param type the annotated configuration type (could be an interface or
- * a non abstract class), not null.
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
- * If no such config is passed, the default configurationa provided by the current
- * registered providers are used.
- * @return the corresponding typed Configuration instance, never null.
- * @throws ConfigException if the configuration could not be resolved.
- */
- public static <T> T createTemplate(Class<T> type, Configuration... configurations){
- return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).createTemplate(type, configurations);
- }
-
- /**
- * Configures an instance, by resolving and injecting the configuration
- * entries.
- *
- * @param instance the instance with configuration annotations, not null.
- * @param configurations the configurations to be used for evaluating the values for injection into {@code instance}.
- * If no items are passed, the default configuration is used.
- * @throws ConfigException if the configuration could not be resolved.
- */
- public static void configure(Object instance, Configuration... configurations){
- ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).configure(instance, configurations);
- }
-
- /**
- * Evaluate the current expression based on the current configuration valid.
- *
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
- * If no such config is passed, the default configurationa provided by the current
- * registered providers are used.
- * @param expression the expression, not null.
- * @return the evaluated config expression.
- */
- public static String evaluateValue(String expression, Configuration... configurations){
- return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).evaluateValue(expression, configurations);
- }
-
- /**
- * Add a ConfigChangeSet listener to the given configuration instance.
- * @param l the listener, not null.
- */
- public static void addChangeListener(Consumer<ConfigChangeSet> l) {
- ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).addChangeListener(Objects.requireNonNull(l));
- }
-
- /**
- * Removes a ConfigChangeSet listener from the given configuration instance.
- * @param l the listener, not null.
- */
- public static void removeChangeListener(Consumer<ConfigChangeSet> l) {
- ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).removeChangeListener(Objects.requireNonNull(l));
- }
-
- /**
- * Method to publish changes on a {@link org.apache.tamaya.Configuration} to all interested parties.
- * Basically this method gives an abstraction on the effective event bus design fo listeners. In a CDI context
- * the CDI enterprise event bus should be used internally to do the work, whereas in a SE only environment
- * a more puristic approach would be useful.
- * @param configChange the change to be published, not null.
- */
- public static void publishChange(ConfigChangeSet configChange) {
- ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).publishChange(Objects.requireNonNull(configChange));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/ConfiguredValue.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/ConfiguredValue.java b/api/src/main/java/org/apache/tamaya/ConfiguredValue.java
new file mode 100644
index 0000000..839e67e
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/ConfiguredValue.java
@@ -0,0 +1,261 @@
+/*
+ * 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;
+
+import org.apache.tamaya.annotation.LoadPolicy;
+
+import java.beans.PropertyChangeEvent;
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+
+/**
+ * A accessor for a single configured value. This can be used to support values that may be reinjected, reconfigured.
+ * <h3>Implementation Requirements</h3>
+ * Instances of this class must be
+ * <ul>
+ * <li>Serializable</li>
+ * <li>Immutable</li>
+ * <li>Thread safe</li>
+ * </ul>
+ */
+public interface ConfiguredValue<T> {
+
+ /**
+ * Access the {@link org.apache.tamaya.annotation.LoadPolicy} used for updating this value.
+ * @return the load policy, never null.
+ */
+ LoadPolicy getLoadPolicy();
+
+ /**
+ * get the UTC timestamp in ms of the last access to a value, using get().
+ * @return the UTC timestamp of the last access
+ */
+ long getLastAccess();
+
+ /**
+ * get the UTC timestamp in ms of the last update to the value,.
+ * @return the UTC timestamp of the last update
+ */
+ long getLastUpdate();
+
+ /**
+ * Access if this instance has been updated since the given UTC timestamp in ms.
+ * @param timestamp
+ * @return true, if his instance has been updated since the given UTC timestamp in ms.
+ */
+ boolean isUpdatedSince(long timestamp);
+
+ /**
+ * Access if this instance has been accessed since the given UTC timestamp in ms.
+ * @param timestamp
+ * @return true, if his instance has been accessed since the given UTC timestamp in ms.
+ */
+ boolean isAccessedSince(long timestamp);
+
+ /**
+ * Add a listener to be called, when this value is changed.
+ * @param l the listner, not null
+ */
+ void addListener(Consumer<PropertyChangeEvent> l);
+
+ /**
+ * Removes a listener to be called, when this value is changed.
+ * @param l the listner to be removed, not null
+ */
+ void removeListener(Consumer<PropertyChangeEvent> l);
+
+ /**
+ * Get some descriptive meta info on the current value.
+ * @return the meta info, not null.
+ */
+ String getMetaInfo();
+
+ /**
+ * Evaluate if the item value has been updated since the last access.
+ * @return true, if item value has been updated since the last access.
+ */
+ default boolean isUpdated(){
+ return isUpdatedSince(getLastAccess());
+ }
+
+ /**
+ * If a value is present in this {@code ConfiguredValue}, returns the value,
+ * otherwise throws {@code ConfigException}.
+ *
+ * @return the non-null value held by this {@code Optional}
+ * @throws org.apache.tamaya.ConfigException if there is no value present
+ *
+ * @see ConfiguredValue#isPresent()
+ */
+ T get();
+
+ /**
+ * If a value is present in this {@code ConfiguredValue}, returns the value,
+ * otherwise throws {@code ConfigException}.
+ *
+ * @return the non-null value held by this {@code Optional}
+ * @throws org.apache.tamaya.ConfigException if there is no value present
+ *
+ * @see ConfiguredValue#isPresent()
+ */
+ default T updateAndGet(){
+ update();
+ return get();
+ }
+
+ /**
+ * Reevaluates the current value based on the instance's settings from the underlying configurations
+ * and applies the new value to its internal state. On change any registered listeners will be triggered.
+ */
+ void update();
+
+ /**
+ * Return {@code true} if there is a value present, otherwise {@code false}.
+ *
+ * @return {@code true} if there is a value present, otherwise {@code false}
+ */
+ boolean isPresent();
+
+ /**
+ * If a value is present, invoke the specified consumer with the value,
+ * otherwise do nothing.
+ *
+ * @param consumer block to be executed if a value is present
+ * @throws NullPointerException if value is present and {@code consumer} is
+ * null
+ */
+ void ifPresent(Consumer<? super T> consumer);
+
+ /**
+ * If a value is present, and the value matches the given predicate,
+ * return an {@code Optional} describing the value, otherwise return an
+ * empty {@code Optional}.
+ *
+ * @param predicate a predicate to apply to the value, if present
+ * @return an {@code Optional} describing the value of this {@code Optional}
+ * if a value is present and the value matches the given predicate,
+ * otherwise an empty {@code Optional}
+ * @throws NullPointerException if the predicate is null
+ */
+ ConfiguredValue<T> filter(Predicate<? super T> predicate);
+
+ /**
+ * If a value is present, apply the provided mapping function to it,
+ * and if the result is non-null, return an {@code Optional} describing the
+ * result. Otherwise return an empty {@code Optional}.
+ *
+ * @apiNote This method supports post-processing on optional values, without
+ * the need to explicitly check for a return status. For example, the
+ * following code traverses a stream of file names, selects one that has
+ * not yet been processed, and then opens that file, returning an
+ * {@code Optional<FileInputStream>}:
+ *
+ * <pre>{@code
+ * Optional<FileInputStream> fis =
+ * names.stream().filter(name -> !isProcessedYet(name))
+ * .findFirst()
+ * .map(name -> new FileInputStream(name));
+ * }</pre>
+ *
+ * Here, {@code findFirst} returns an {@code Optional<String>}, and then
+ * {@code map} returns an {@code Optional<FileInputStream>} for the desired
+ * file if one exists.
+ *
+ * @param <U> The type of the result of the mapping function
+ * @param mapper a mapping function to apply to the value, if present
+ * @return an {@code Optional} describing the result of applying a mapping
+ * function to the value of this {@code Optional}, if a value is present,
+ * otherwise an empty {@code Optional}
+ * @throws NullPointerException if the mapping function is null
+ */
+ <U> ConfiguredValue<U> map(Function<? super T, ? extends U> mapper);
+
+ /**
+ * If a value is present, apply the provided {@code Optional}-bearing
+ * mapping function to it, return that result, otherwise return an empty
+ * {@code Optional}. This method is similar to {@link #map(Function)},
+ * but the provided mapper is one whose result is already an {@code Optional},
+ * and if invoked, {@code flatMap} does not wrap it with an additional
+ * {@code Optional}.
+ *
+ * @param <U> The type parameter to the {@code Optional} returned by
+ * @param mapper a mapping function to apply to the value, if present
+ * the mapping function
+ * @return the result of applying an {@code Optional}-bearing mapping
+ * function to the value of this {@code Optional}, if a value is present,
+ * otherwise an empty {@code Optional}
+ * @throws NullPointerException if the mapping function is null or returns
+ * a null result
+ */
+ <U> ConfiguredValue<U> flatMap(Function<? super T, ConfiguredValue<U>> mapper);
+
+ /**
+ * Return the value if present, otherwise return {@code other}.
+ *
+ * @param other the value to be returned if there is no value present, may
+ * be null
+ * @return the value, if present, otherwise {@code other}
+ */
+ T orElse(T other);
+
+ /**
+ * Return the value if present, otherwise invoke {@code other} and return
+ * the result of that invocation.
+ *
+ * @param other a {@code Supplier} whose result is returned if no value
+ * is present
+ * @return the value if present otherwise the result of {@code other.get()}
+ * @throws NullPointerException if value is not present and {@code other} is
+ * null
+ */
+ T orElseGet(Supplier<? extends T> other);
+
+ /**
+ * Return the contained value, if present, otherwise throw an exception
+ * to be created by the provided supplier.
+ *
+ * @apiNote A method reference to the exception constructor with an empty
+ * argument list can be used as the supplier. For example,
+ * {@code IllegalStateException::new}
+ *
+ * @param <X> Type of the exception to be thrown
+ * @param exceptionSupplier The supplier which will return the exception to
+ * be thrown
+ * @return the present value
+ * @throws X if there is no value present
+ * @throws NullPointerException if no value is present and
+ * {@code exceptionSupplier} is null
+ */
+ <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X;
+
+ /**
+ * Converts this value to an {@link java.util.Optional} instance.
+ * @return an {@link java.util.Optional} instance, never null.
+ */
+ default Optional<T> toOptional(){
+ if(isPresent()){
+ return Optional.of(get());
+ }
+ return Optional.empty();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/Environment.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/Environment.java b/api/src/main/java/org/apache/tamaya/Environment.java
deleted file mode 100644
index 11e7100..0000000
--- a/api/src/main/java/org/apache/tamaya/Environment.java
+++ /dev/null
@@ -1,83 +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;
-
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-
-/**
- * Models a runtime environment. Instances current this class are used to
- * evaluate the correct configuration artifacts.<br/>
- * <h3>Implementation Requirements</h3>
- * <p>
- * Implementations current this interface must be
- * <ul>
- * <li>Thread safe.
- * <li>Immutable
- * <li>serializable
- * </ul>
- */
-public interface Environment{
-
- /**
- * Access a property.
- * @param key the property's key, not null.
- * @return the property's keys.
- */
- Optional<String> get(String key);
-
- /**
- * Checks if a property is defined.
- * @param key the property's key, not null.
- * @return true, if the property is existing.
- */
- boolean containsKey(String key);
-
- /**
- * Access the set current property keys, defined by this provider.
- * @return the key set, never null.
- */
- Set<String> keySet();
-
- /**
- * Access the environment as Map.
- * @return the Map instance containing the environments properties, never null.
- */
- Map<String,String> toMap();
-
- /**
- * Get the current {@link org.apache.tamaya.Environment}. The environment is used to determine the current runtime state, which
- * is important for returning the correct configuration.
- * @return the current Environment, never null.
- */
- public static Environment current(){
- return EnvironmentManager.getCurrentEnvironment();
- }
-
- /**
- * Get the current {@link org.apache.tamaya.Environment}. The environment is used to determine the current runtime state, which
- * is important for returning the correct configuration.
- * @return the current Environment, never null.
- */
- public static Environment root(){
- return EnvironmentManager.getRootEnvironment();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/EnvironmentManager.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/EnvironmentManager.java b/api/src/main/java/org/apache/tamaya/EnvironmentManager.java
deleted file mode 100644
index 1c60d95..0000000
--- a/api/src/main/java/org/apache/tamaya/EnvironmentManager.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;
-
-import org.apache.tamaya.spi.EnvironmentManagerSingletonSpi;
-import org.apache.tamaya.spi.ServiceContext;
-
-
-/**
- * Singleton accessor class for the current environment.
- */
-final class EnvironmentManager{
-
- /**
- * Private singleton constructor.
- */
- private EnvironmentManager(){}
-
- /**
- * Get the current {@link Environment}. The environment is used to determine the current runtime state, which
- * is important for returning the correct configuration.
- * @return the current Environment, never null.
- */
- public static Environment getCurrentEnvironment(){
- return ServiceContext.getInstance().getSingleton(EnvironmentManagerSingletonSpi.class).getCurrentEnvironment();
- }
-
- /**
- * Get the root {@link Environment}. The environment is used to determine the current runtime state, which
- * is important for returning the correct configuration.
- * @return the root Environment, never null.
- */
- public static Environment getRootEnvironment(){
- return ServiceContext.getInstance().getSingleton(EnvironmentManagerSingletonSpi.class).getRootEnvironment();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/PropertySource.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/PropertySource.java b/api/src/main/java/org/apache/tamaya/PropertySource.java
index 9179c8f..2cd3af7 100644
--- a/api/src/main/java/org/apache/tamaya/PropertySource.java
+++ b/api/src/main/java/org/apache/tamaya/PropertySource.java
@@ -18,10 +18,7 @@
*/
package org.apache.tamaya;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
+import java.util.*;
/**
* This interface models a provider that serves configuration properties. The contained
@@ -48,30 +45,35 @@ public interface PropertySource {
*/
public static final PropertySource EMPTY_PROPERTYSOURCE = new PropertySource() {
- private MetaInfo metaInfo = MetaInfo.of("<empty>");
-
@Override
- public Optional<String> get(String key) {
- return Optional.empty();
+ public String getName() {
+ return "<empty>";
}
@Override
- public boolean containsKey(String key) {
- return false;
+ public Optional<String> get(String key) {
+ return Optional.empty();
}
@Override
- public Map<String, String> toMap() {
+ public Map<String, String> getProperties() {
return Collections.emptyMap();
}
@Override
- public MetaInfo getMetaInfo() {
- return metaInfo;
+ public String toString(){
+ return "PropertySource [name=<empty>]";
}
};
/**
+ * Get the name of the property source. The name should be unique for the type of source, whereas the id is used
+ * to ensure unique identity, either locally or remotely.
+ * @return the configuration's name, never null.
+ */
+ String getName();
+
+ /**
* Access a property.
*
* @param key the property's key, not null.
@@ -80,47 +82,35 @@ public interface PropertySource {
Optional<String> get(String key);
/**
- * Get the meta-info current a configuration.
+ * Access the current properties as Map. The resulting Map may not return all items accessible, e.g.
+ * when the underlying storage does not support iteration of its entries.
*
- * @return the configuration's/config map's metaInfo, or null.
- */
- MetaInfo getMetaInfo();
-
- /**
- * Checks if a property is defined/accessible.
- * @throws java.lang.UnsupportedOperationException If the underlying storage does not support introspection.
- * @param key the property's key, not null.
- * @return true, if the property is existing.
+ * @return the a corresponding map, never null.
*/
- boolean containsKey(String key);
+ Map<String, String> getProperties();
/**
- * Allows to quickly check, if a provider is empty.
- * @return true, if the provier is empty.
+ * Determines if this config source should be scanned for its list of properties.
+ *
+ * Generally, slow ConfigSources should return false here.
+ *
+ * @return true if this ConfigSource should be scanned for its list of properties,
+ * false if it should not be scanned.
*/
- default boolean isEmpty(){
- return keySet().isEmpty();
+ default boolean isScannable(){
+ return true;
}
/**
- * Access the set current property keys, defined by this provider. The resulting Set may not return all keys
- * accessible, e.g. when the underlying storage does not support iteration of its entries.
+ * Allows to quickly check, if a provider is empty.
*
- * @return the key set, never null.
+ * @return true, if the provier is empty.
*/
- default Set<String> keySet() {
- return toMap().keySet();
+ default boolean isEmpty() {
+ return getProperties().isEmpty();
}
/**
- * Access the current properties as Map. The resulting Map may not return all items accessible, e.g.
- * when the underlying storage does not support iteration of its entries.
- * @return the a corresponding map, never null.
- */
- Map<String, String> toMap();
-
-
- /**
* Reloads the {@link PropertySource}.
*/
default ConfigChangeSet load() {
@@ -158,24 +148,48 @@ public interface PropertySource {
default Configuration toConfiguration() {
return new Configuration() {
@Override
- public Optional<String> get(String key) {
- return PropertySource.this.get(key);
+ public String getName() {
+ return PropertySource.this.getName();
+ }
+
+ @Override
+ public boolean isScannable() {
+ return PropertySource.this.isScannable();
+ }
+
+ @Override
+ public boolean isMutable() {
+ return PropertySource.this.isMutable();
}
+
+ @Override
+ public void applyChanges(ConfigChangeSet changes) {
+ PropertySource.this.applyChanges(changes);
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return PropertySource.this.isEmpty();
+ }
+
@Override
- public boolean containsKey(String key) {
- return PropertySource.this.containsKey(key);
+ public ConfigChangeSet load() {
+ return PropertySource.this.load();
}
+
@Override
- public Map<String, String> toMap() {
- return PropertySource.this.toMap();
+ public Optional<String> get(String key) {
+ return PropertySource.this.get(key);
}
+
@Override
- public MetaInfo getMetaInfo() {
- return PropertySource.this.getMetaInfo();
+ public Map<String, String> getProperties() {
+ return PropertySource.this.getProperties();
}
+
@Override
public String toString() {
- return "Configuration [source: PropertySource "+getMetaInfo()+"]";
+ return "Configuration [name: " + getName() + "]";
}
};
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/annotation/NoConfig.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/annotation/NoConfig.java b/api/src/main/java/org/apache/tamaya/annotation/NoConfig.java
new file mode 100644
index 0000000..845ec4c
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/annotation/NoConfig.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.annotation;
+
+import java.lang.annotation.*;
+
+/**
+ * This is a small marker annotations to inform Tamaya that the annotated element should never be injected with
+ * configured data. This is useful because by default Tamaya tries to lookup and inject configuration also by
+ * using property or method names without annotations. With that annotation none of these will be happen.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.METHOD })
+public @interface NoConfig {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/spi/CodecSpi.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/CodecSpi.java b/api/src/main/java/org/apache/tamaya/spi/CodecSpi.java
new file mode 100644
index 0000000..7a0670b
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/spi/CodecSpi.java
@@ -0,0 +1,89 @@
+/*
+ * 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.spi;
+
+import org.apache.tamaya.Codec;
+import org.apache.tamaya.annotation.WithCodec;
+
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * SPI that is used by the {@link org.apache.tamaya.Codecs} singleton as delegation instance.
+ */
+public interface CodecSpi {
+
+ /**
+ * Registers a new PropertyAdapter for the given target type, hereby replacing any existing adapter for
+ * this type.
+ * @param targetType The target class, not null.
+ * @param adapter The adapter, not null.
+ * @param <T> The target type
+ * @return any adapter replaced with the new adapter, or null.
+ */
+ <T> Codec<T> register(Class<T> targetType, Codec<T> adapter);
+
+ default <T> Codec<T> register(Class<T> targetType, Function<String,T> decoder, Function<T, String> encoder){
+ Objects.requireNonNull(targetType);
+ Objects.requireNonNull(decoder);
+ Objects.requireNonNull(encoder);
+ return register(targetType, new Codec<T>(){
+
+ @Override
+ public T deserialize(String value) {
+ return decoder.apply(value);
+ }
+
+ @Override
+ public String serialize(T value) {
+ return encoder.apply(value);
+ }
+
+ @Override
+ public String toString(){
+ return "Codec(decoder="+decoder.getClass().getName()+", encoder="+encoder.getClass().getName()+")";
+ }
+ });
+ }
+
+ /**
+ * Get an adapter converting to the given target type.
+ * @param targetType the target type class
+ * @return true, if the given target type is supported.
+ */
+ default <T> Codec<T> getAdapter(Class<T> targetType){
+ return getCodec(targetType, null);
+ }
+
+ /**
+ * Get an adapter converting to the given target type.
+ * @param targetType the target type class
+ * @param <T> the target type
+ * @return the corresponding adapter, never null.
+ * @throws org.apache.tamaya.ConfigException if the target type is not supported.
+ */
+ <T> Codec<T> getCodec(Class<T> targetType, WithCodec annotation);
+
+ /**
+ * Checks if the given target type is supported, i.e. a adapter is registered and accessible.
+ * @param targetType the target type class
+ * @return true, if the given target type is supported.
+ */
+ boolean isTargetTypeSupported(Class<?> targetType);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/spi/CodecsSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/CodecsSingletonSpi.java b/api/src/main/java/org/apache/tamaya/spi/CodecsSingletonSpi.java
deleted file mode 100644
index 07993e5..0000000
--- a/api/src/main/java/org/apache/tamaya/spi/CodecsSingletonSpi.java
+++ /dev/null
@@ -1,89 +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.spi;
-
-import org.apache.tamaya.Codec;
-import org.apache.tamaya.annotation.WithCodec;
-
-import java.util.Objects;
-import java.util.function.Function;
-
-/**
- * SPI that is used by the {@link org.apache.tamaya.Codecs} singleton as delegation instance.
- */
-public interface CodecsSingletonSpi {
-
- /**
- * Registers a new PropertyAdapter for the given target type, hereby replacing any existing adapter for
- * this type.
- * @param targetType The target class, not null.
- * @param adapter The adapter, not null.
- * @param <T> The target type
- * @return any adapter replaced with the new adapter, or null.
- */
- <T> Codec<T> register(Class<T> targetType, Codec<T> adapter);
-
- default <T> Codec<T> register(Class<T> targetType, Function<String,T> decoder, Function<T, String> encoder){
- Objects.requireNonNull(targetType);
- Objects.requireNonNull(decoder);
- Objects.requireNonNull(encoder);
- return register(targetType, new Codec<T>(){
-
- @Override
- public T deserialize(String value) {
- return decoder.apply(value);
- }
-
- @Override
- public String serialize(T value) {
- return encoder.apply(value);
- }
-
- @Override
- public String toString(){
- return "Codec(decoder="+decoder.getClass().getName()+", encoder="+encoder.getClass().getName()+")";
- }
- });
- }
-
- /**
- * Get an adapter converting to the given target type.
- * @param targetType the target type class
- * @return true, if the given target type is supported.
- */
- default <T> Codec<T> getAdapter(Class<T> targetType){
- return getCodec(targetType, null);
- }
-
- /**
- * Get an adapter converting to the given target type.
- * @param targetType the target type class
- * @param <T> the target type
- * @return the corresponding adapter, never null.
- * @throws org.apache.tamaya.ConfigException if the target type is not supported.
- */
- <T> Codec<T> getCodec(Class<T> targetType, WithCodec annotation);
-
- /**
- * Checks if the given target type is supported, i.e. a adapter is registered and accessible.
- * @param targetType the target type class
- * @return true, if the given target type is supported.
- */
- boolean isTargetTypeSupported(Class<?> targetType);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/spi/ConfigurationManagerSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/ConfigurationManagerSingletonSpi.java b/api/src/main/java/org/apache/tamaya/spi/ConfigurationManagerSingletonSpi.java
deleted file mode 100644
index 6be15a8..0000000
--- a/api/src/main/java/org/apache/tamaya/spi/ConfigurationManagerSingletonSpi.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spi;
-
-import org.apache.tamaya.ConfigChangeSet;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertySource;
-
-import java.util.function.Consumer;
-import java.util.function.Predicate;
-
-/**
- * Manager for {@link org.apache.tamaya.Configuration} instances. Implementations must register an instance
- * using the {@link ServiceContextManager} mechanism in place (by default this is based on the {@link java.util.ServiceLoader}.
- * The {@link org.apache.tamaya.ConfigurationManager} Singleton in the API delegates its corresponding calls to the
- * instance returned by the current bootstrap service in place.
- *
- * @see org.apache.tamaya.ConfigurationManager
- * @see ServiceContextManager
- */
-public interface ConfigurationManagerSingletonSpi{
-
- /**
- * Allows to check if a configuration with a given name is defined.
- * @param name the configuration's name, not null, not empty.
- * @return true, if such a configuration is defined.
- */
- boolean isConfigurationDefined(String name);
-
- /**
- * Access a configuration by name.
- * @param name the configuration's name, not null, not empty.
- * @return the corresponding Configuration instance, never null.
- * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
- */
- Configuration getConfiguration(String name);
-
- /**
- * Access the default configuration.
- * @return the corresponding Configuration instance, never null.
- * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
- */
- default Configuration getConfiguration(){
- return getConfiguration("default");
- }
-
- /**
- * Configures an instance, by resolving and injecting the configuration
- * entries.
- *
- * @param instance the instance with configuration annotations, not null.
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}.
- * If no such config is passed, the default configurationa provided by the current
- * registered providers are used.
- * @throws org.apache.tamaya.ConfigException if any required configuration could not be resolved/injected.
- */
- void configure(Object instance, Configuration... configurations);
-
- /**
- * Access a configuration by name.
- *
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
- * If no such config is passed, the default configurationa provided by the current
- * registered providers are used.
- * @return the corresponding Configuration instance, never null.
- * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
- */
- <T> T createTemplate(Class<T> template, Configuration... configurations);
-
- /**
- * Evaluate the current expression based on the current configuration valid.
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
- * If no such config is passed, the default configurationa provided by the current
- * registered providers are used.
- * @param expression the expression, not null.
- * @return the evaluated config expression.
- */
- String evaluateValue(String expression, Configuration... configurations);
-
- /**
- * Add a ConfigChangeSet listener to the given configuration instance.
- * @@param l the listener, not null.
- */
- void addChangeListener(Consumer<ConfigChangeSet> l);
-
- /**
- * Removes a ConfigChangeSet listener from the given configuration instance.
- * @param l the listener, not null.
- */
- void removeChangeListener(Consumer<ConfigChangeSet> l);
-
- /**
- * Method to publish changes on a {@link org.apache.tamaya.Configuration} to all interested parties.
- * Basically this method gives an abstraction on the effective event bus design fo listeners. In a CDI context
- * the CDI enterprise event bus should be used internally to do the work, whereas in a SE only environment
- * a more puristic approach would be useful.
- * @param configChangeSet the change to be published, not null.
- */
- void publishChange(ConfigChangeSet configChangeSet);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java b/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java
new file mode 100644
index 0000000..a5979a8
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java
@@ -0,0 +1,116 @@
+/*
+ * 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.spi;
+
+import org.apache.tamaya.ConfigChangeSet;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.PropertySource;
+
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+
+/**
+ * Manager for {@link org.apache.tamaya.Configuration} instances. Implementations must register an instance
+ * using the {@link ServiceContextManager} mechanism in place (by default this is based on the {@link java.util.ServiceLoader}.
+ * The {@link org.apache.tamaya.ConfigurationManager} Singleton in the API delegates its corresponding calls to the
+ * instance returned by the current bootstrap service in place.
+ *
+ * @see org.apache.tamaya.ConfigurationManager
+ * @see ServiceContextManager
+ */
+public interface ConfigurationSpi {
+
+ /**
+ * Allows to check if a configuration with a given name is defined.
+ * @param name the configuration's name, not null, not empty.
+ * @return true, if such a configuration is defined.
+ */
+ boolean isConfigurationAvailable(String name);
+
+ /**
+ * Access a configuration by name.
+ * @param name the configuration's name, not null, not empty.
+ * @return the corresponding Configuration instance, never null.
+ * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
+ */
+ Configuration getConfiguration(String name);
+
+ /**
+ * Access the default configuration.
+ * @return the corresponding Configuration instance, never null.
+ * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
+ */
+ default Configuration getConfiguration(){
+ return getConfiguration("default");
+ }
+
+ /**
+ * Configures an instance, by resolving and injecting the configuration
+ * entries.
+ *
+ * @param instance the instance with configuration annotations, not null.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
+ * @throws org.apache.tamaya.ConfigException if any required configuration could not be resolved/injected.
+ */
+ void configure(Object instance, Configuration... configurations);
+
+ /**
+ * Access a configuration by name.
+ *
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
+ * @return the corresponding Configuration instance, never null.
+ * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
+ */
+ <T> T createTemplate(Class<T> template, Configuration... configurations);
+
+ /**
+ * Evaluate the current expression based on the current configuration valid.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
+ * @param expression the expression, not null.
+ * @return the evaluated config expression.
+ */
+ String evaluateValue(String expression, Configuration... configurations);
+
+ /**
+ * Add a ConfigChangeSet listener to the given configuration instance.
+ * @@param l the listener, not null.
+ */
+ void addChangeListener(Consumer<ConfigChangeSet> l);
+
+ /**
+ * Removes a ConfigChangeSet listener from the given configuration instance.
+ * @param l the listener, not null.
+ */
+ void removeChangeListener(Consumer<ConfigChangeSet> l);
+
+ /**
+ * Method to publish changes on a {@link org.apache.tamaya.Configuration} to all interested parties.
+ * Basically this method gives an abstraction on the effective event bus design fo listeners. In a CDI context
+ * the CDI enterprise event bus should be used internally to do the work, whereas in a SE only environment
+ * a more puristic approach would be useful.
+ * @param configChangeSet the change to be published, not null.
+ */
+ void publishChange(ConfigChangeSet configChangeSet);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/spi/EnvironmentManagerSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/EnvironmentManagerSingletonSpi.java b/api/src/main/java/org/apache/tamaya/spi/EnvironmentManagerSingletonSpi.java
deleted file mode 100644
index 84ac864..0000000
--- a/api/src/main/java/org/apache/tamaya/spi/EnvironmentManagerSingletonSpi.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.spi;
-
-
-import org.apache.tamaya.Environment;
-
-/**
- * Service for accessing {@link org.apache.tamaya.Environment}. Environments are used to
- * access/determine configurations.<br/>
- * <h3>Implementation PropertyMapSpec</h3> This class is
- * <ul>
- * <li>thread safe,
- * <li>and behaves contextual.
- * </ul>
- */
-public interface EnvironmentManagerSingletonSpi{
-
- /**
- * Get the current environment current the given environment type.
- * @return the corresponding environment, never null.
- * @throws IllegalArgumentException if not such type is present or active.
- */
- Environment getCurrentEnvironment();
-
- /**
- * Get the current environment current the given environment type.
- * @return the corresponding environment, never null.
- * @throws IllegalArgumentException if not such type is present or active.
- */
- Environment getRootEnvironment();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java b/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
index 89f8078..0ec2aa0 100644
--- a/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
+++ b/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
@@ -22,14 +22,13 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
-import java.util.function.Predicate;
-import org.apache.tamaya.spi.ConfigurationManagerSingletonSpi;
+import org.apache.tamaya.spi.ConfigurationSpi;
/**
* Created by Anatole on 09.09.2014.
*/
-public class TestConfigServiceSingletonSpi implements ConfigurationManagerSingletonSpi{
+public class TestConfigServiceSingletonSpi implements ConfigurationSpi {
private Map<String, Configuration> configs = new ConcurrentHashMap<>();
@@ -55,7 +54,7 @@ public class TestConfigServiceSingletonSpi implements ConfigurationManagerSingle
@Override
- public boolean isConfigurationDefined(String name){
+ public boolean isConfigurationAvailable(String name){
return configs.containsKey(name);
}
@@ -81,7 +80,7 @@ public class TestConfigServiceSingletonSpi implements ConfigurationManagerSingle
public String evaluateValue(String expression, Configuration... configurations) {
// TODO improve this ugly implementation...
for (Configuration config : configurations) {
- for (Map.Entry<String, String> en : config.toMap().entrySet()) {
+ for (Map.Entry<String, String> en : config.getProperties().entrySet()) {
expression = expression.replaceAll("\\$\\{" + en.getKey() + "\\}", en.getValue());
}
}
[2/6] incubator-tamaya git commit: TAMAYA-19: - Moved out much of
unused/experimental code. - Reduced API (removing package private singletons)
- Aligned PropertySource with Deltaspike (mostly). - Moved Environment model
to separate metamodel module.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.EnvironmentProvider
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.EnvironmentProvider b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.EnvironmentProvider
deleted file mode 100644
index 3592434..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.EnvironmentProvider
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy 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.core.internal.env.InitialEnvironmentProvider
-org.apache.tamaya.core.internal.env.SystemClassLoaderEnvironmentProvider
-org.apache.tamaya.core.internal.env.ClassLoaderDependentEarEnvironmentProvider
-org.apache.tamaya.core.internal.env.ClassLoaderDependentApplicationEnvironmentProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.CodecSpi
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.CodecSpi b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.CodecSpi
new file mode 100644
index 0000000..c0a61aa
--- /dev/null
+++ b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.CodecSpi
@@ -0,0 +1,19 @@
+#
+# 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.core.internal.config.DefaultCodecSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi
deleted file mode 100644
index 599b50f..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.core.internal.properties.DefaultCodecsSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationManagerSingletonSpi
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationManagerSingletonSpi b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationManagerSingletonSpi
deleted file mode 100644
index 1020ab5..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationManagerSingletonSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.core.internal.config.DefaultConfigurationManagerSingletonSpi
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
new file mode 100644
index 0000000..2764092
--- /dev/null
+++ b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
@@ -0,0 +1,19 @@
+#
+# 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.core.internal.config.DefaultConfigurationSpi
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentManagerSingletonSpi
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentManagerSingletonSpi b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentManagerSingletonSpi
deleted file mode 100644
index b1a7ea5..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentManagerSingletonSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.core.internal.env.SingleEnvironmentManager
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.StagesSingletonSpi
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.StagesSingletonSpi b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.StagesSingletonSpi
deleted file mode 100644
index 40575b2..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.StagesSingletonSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.core.internal.env.DefaultStagesSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/java/org/apache/tamaya/DefaultConfigurationManagerSingletonSpiSingletonSpiTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/DefaultConfigurationManagerSingletonSpiSingletonSpiTest.java b/core/src/test/java/org/apache/tamaya/DefaultConfigurationManagerSingletonSpiSingletonSpiTest.java
index 1c1559a..2ee83a9 100644
--- a/core/src/test/java/org/apache/tamaya/DefaultConfigurationManagerSingletonSpiSingletonSpiTest.java
+++ b/core/src/test/java/org/apache/tamaya/DefaultConfigurationManagerSingletonSpiSingletonSpiTest.java
@@ -25,18 +25,18 @@ import static org.junit.Assert.assertTrue;
import org.apache.tamaya.annotation.ConfiguredProperty;
import org.apache.tamaya.annotation.DefaultValue;
-import org.apache.tamaya.core.internal.config.DefaultConfigurationManagerSingletonSpi;
+import org.apache.tamaya.core.internal.config.DefaultConfigurationSpi;
import org.junit.Test;
/**
- * Test class for {@link org.apache.tamaya.core.internal.config.DefaultConfigurationManagerSingletonSpi}.
+ * Test class for {@link org.apache.tamaya.core.internal.config.DefaultConfigurationSpi}.
*/
public class DefaultConfigurationManagerSingletonSpiSingletonSpiTest {
@Test
public void testSEConfigurationService() {
- new DefaultConfigurationManagerSingletonSpi();
+ new DefaultConfigurationSpi();
}
@Test
@@ -44,41 +44,24 @@ public class DefaultConfigurationManagerSingletonSpiSingletonSpiTest {
Configuration config = Configuration.current("default");
assertNotNull(config);
assertTrue(config.toString().contains("default"));
- assertNotNull(config.getMetaInfo());
- assertTrue(config.getMetaInfo().toString().contains("default"));
+ assertNotNull(config.getName());
+ assertTrue(config.getName().contains("default"));
System.out.println("CONFIG: " + config);
assertEquals(System.getProperty("java.version"),
config.get("java.version").get());
config = Configuration.current("system.properties");
assertNotNull(config);
- assertNotNull(config.getMetaInfo());
- assertTrue(config.getMetaInfo().toString().contains("system.properties"));
+ assertNotNull(config.getName());
+ assertTrue(config.getName().contains("system.properties"));
assertEquals(System.getProperty("java.version"),
config.get("java.version").get());
}
@Test
public void testIsConfigurationDefined() {
- assertTrue(Configuration.isDefined("test"));
- assertFalse(Configuration.isDefined("sdksajdsajdlkasj dlkjaslkd"));
- }
-
- @Test
- public void testGetCurrentEnvironment() {
- Environment env = Environment.current();
- assertNotNull(env);
- assertEquals(System.getProperty("java.version"),
- env.get("java.version").get());
- }
-
- @Test
- public void testGetRootEnvironment() {
-// DefaultConfigurationManagerSingletonSpi s = new DefaultConfigurationManagerSingletonSpi();
- Environment env = Environment.root();
- assertNotNull(env);
- assertEquals(System.getProperty("java.version"),
- env.get("java.version").get());
+ assertTrue(Configuration.isAvailable("test"));
+ assertFalse(Configuration.isAvailable("sdksajdsajdlkasj dlkjaslkd"));
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/JavaOneDemo.java b/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
index 4287e68..e4c93ef 100644
--- a/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
+++ b/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertNotNull;
import java.util.HashMap;
import java.util.Map;
+import org.apache.tamaya.core.config.ConfigFunctions;
import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.junit.Test;
@@ -56,13 +57,13 @@ public class JavaOneDemo {
"classpath:test.properties").addPaths("classpath:cfg/test.xml")
.addArgs(new String[]{"-arg1", "--fullarg", "fullValue", "-myflag"})
.addMap(cfgMap).build().toConfiguration();
- System.out.println(config.getAreas());
+ System.out.println(config.query(ConfigFunctions.getAreas()));
System.out.println("---");
- System.out.println(config.getAreas(s -> s.startsWith("another")));
+ System.out.println(config.query(ConfigFunctions.getAreas(s -> s.startsWith("another"))));
System.out.println("---");
- System.out.println(config.getTransitiveAreas());
+ System.out.println(config.query(ConfigFunctions.getTransitiveAreas()));
System.out.println("---");
- System.out.println(config.getTransitiveAreas(s -> s.startsWith("another")));
+ System.out.println(config.query(ConfigFunctions.getTransitiveAreas(s -> s.startsWith("another"))));
System.out.println("---");
System.out.println(config);
System.out.print("--- b=");
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/java/org/apache/tamaya/core/config/ConfiguredSystemPropertiesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/config/ConfiguredSystemPropertiesTest.java b/core/src/test/java/org/apache/tamaya/core/config/ConfiguredSystemPropertiesTest.java
new file mode 100644
index 0000000..7790d8b
--- /dev/null
+++ b/core/src/test/java/org/apache/tamaya/core/config/ConfiguredSystemPropertiesTest.java
@@ -0,0 +1,94 @@
+///*
+// * Licensed to the Apache Software Foundation (ASF) under one
+// * or more contributor license agreements. See the NOTICE file
+// * distributed with this work for additional information
+// * regarding copyright ownership. The ASF licenses this file
+// * to you under the Apache License, Version 2.0 (the
+// * "License"); you may not use this file except in compliance
+// * with the License. You may obtain a copy of the License at
+// *
+// * http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing,
+// * software distributed under the License is distributed on an
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// * KIND, either express or implied. See the License for the
+// * specific language governing permissions and limitations
+// * under the License.
+// */
+//package org.apache.tamaya.core.config;
+//
+//import static org.junit.Assert.assertTrue;
+//
+//import java.util.Properties;
+//
+//import org.apache.tamaya.core.env.ConfiguredSystemProperties;
+//import org.junit.Test;
+//
+///**
+// * Created by Anatole on 02.10.2014.
+// */
+//public class ConfiguredSystemPropertiesTest {
+//
+// @Test
+// public void testInstall(){
+//// Configuration config = Configuration.current();
+// Properties props = System.getProperties();
+// assertTrue(props.getClass().getName().equals(Properties.class.getName()));
+// System.out.println("Props("+props.getClass().getName()+"): " + props);
+// ConfiguredSystemProperties.install();
+// props = System.getProperties();
+// System.out.println("Props("+props.getClass().getName()+"): " + props);
+// assertTrue(props.getClass().getName().equals(ConfiguredSystemProperties.class.getName()));
+// ConfiguredSystemProperties.uninstall();
+// props = System.getProperties();
+// assertTrue(props.getClass().getName().equals(Properties.class.getName()));
+// }
+//}
+///*
+// * Licensed to the Apache Software Foundation (ASF) under one
+// * or more contributor license agreements. See the NOTICE file
+// * distributed with this work for additional information
+// * regarding copyright ownership. The ASF licenses this file
+// * to you under the Apache License, Version 2.0 (the
+// * "License"); you may not use this file except in compliance
+// * with the License. You may obtain a copy of the License at
+// *
+// * http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing,
+// * software distributed under the License is distributed on an
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// * KIND, either express or implied. See the License for the
+// * specific language governing permissions and limitations
+// * under the License.
+// */
+//package org.apache.tamaya.core.config;
+//
+//import static org.junit.Assert.assertTrue;
+//
+//import java.util.Properties;
+//
+//import org.apache.tamaya.core.env.ConfiguredSystemProperties;
+//import org.junit.Test;
+//
+///**
+// * Created by Anatole on 02.10.2014.
+// */
+//public class ConfiguredSystemPropertiesTest {
+//
+// @Test
+// public void testInstall(){
+//// Configuration config = Configuration.current();
+// Properties props = System.getProperties();
+// assertTrue(props.getClass().getName().equals(Properties.class.getName()));
+// System.out.println("Props("+props.getClass().getName()+"): " + props);
+// ConfiguredSystemProperties.install();
+// props = System.getProperties();
+// System.out.println("Props("+props.getClass().getName()+"): " + props);
+// assertTrue(props.getClass().getName().equals(ConfiguredSystemProperties.class.getName()));
+// ConfiguredSystemProperties.uninstall();
+// props = System.getProperties();
+// assertTrue(props.getClass().getName().equals(Properties.class.getName()));
+// }
+//}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/java/org/apache/tamaya/core/config/EnvironmentManagerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/config/EnvironmentManagerTest.java b/core/src/test/java/org/apache/tamaya/core/config/EnvironmentManagerTest.java
deleted file mode 100644
index d7ae7a4..0000000
--- a/core/src/test/java/org/apache/tamaya/core/config/EnvironmentManagerTest.java
+++ /dev/null
@@ -1,40 +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.core.config;
-
-import org.apache.tamaya.Environment;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Created by Anatole on 16.06.2014.
- */
-public class EnvironmentManagerTest{
-
- @Test
- public void testEnvironmentNotNull(){
- Assert.assertNotNull(Environment.current());
- }
-
- @Test
- public void testRootEnvironmentNotNull(){
- Assert.assertNotNull(Environment.root());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/java/org/apache/tamaya/core/env/ConfiguredSystemPropertiesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/env/ConfiguredSystemPropertiesTest.java b/core/src/test/java/org/apache/tamaya/core/env/ConfiguredSystemPropertiesTest.java
deleted file mode 100644
index 8869ce4..0000000
--- a/core/src/test/java/org/apache/tamaya/core/env/ConfiguredSystemPropertiesTest.java
+++ /dev/null
@@ -1,46 +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.core.env;
-
-import static org.junit.Assert.assertTrue;
-
-import java.util.Properties;
-
-import org.junit.Test;
-
-/**
- * Created by Anatole on 02.10.2014.
- */
-public class ConfiguredSystemPropertiesTest {
-
- @Test
- public void testInstall(){
-// Configuration config = Configuration.current();
- Properties props = System.getProperties();
- assertTrue(props.getClass().getName().equals(Properties.class.getName()));
- System.out.println("Props("+props.getClass().getName()+"): " + props);
- ConfiguredSystemProperties.install();
- props = System.getProperties();
- System.out.println("Props("+props.getClass().getName()+"): " + props);
- assertTrue(props.getClass().getName().equals(ConfiguredSystemProperties.class.getName()));
- ConfiguredSystemProperties.uninstall();
- props = System.getProperties();
- assertTrue(props.getClass().getName().equals(Properties.class.getName()));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/java/org/apache/tamaya/core/env/EnvironmentManagerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/env/EnvironmentManagerTest.java b/core/src/test/java/org/apache/tamaya/core/env/EnvironmentManagerTest.java
deleted file mode 100644
index 3a6b033..0000000
--- a/core/src/test/java/org/apache/tamaya/core/env/EnvironmentManagerTest.java
+++ /dev/null
@@ -1,66 +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.core.env;
-
-import org.apache.tamaya.Environment;
-import org.junit.Test;
-
-
-import static org.junit.Assert.*;
-
-/**
- * Tests for basic {@link org.apache.tamaya.EnvironmentManager} functionality.
- * Created by Anatole on 17.10.2014.
- */
-public class EnvironmentManagerTest {
-
- @Test
- public void testGetEnvironment(){
- Environment env = Environment.current();
- assertNotNull(env);
- Environment env2 = Environment.current();
- assertNotNull(env2);
- assertFalse("Current Environments requested in same context are not the same!", env==env2);
- }
-
- @Test
- public void testGetRootEnvironment(){
- Environment env = Environment.root();
- assertNotNull(env);
- Environment env2 = Environment.root();
- assertNotNull(env2);
- assertTrue("Root Environments requested in same context are not the same!", env==env2);
- }
-
- @Test
- public void testRootIsNotCurrentEnvironment(){
- Environment env1 = Environment.root();
- Environment env2 = Environment.current();
- assertNotNull(env1);
- assertNotNull(env2);
- // within this test environment these are always the same
- assertEquals(env1, env2);
- }
-
- @Test
- public void testEnvironmentOverride(){
- assertEquals(Environment.root().get("user.country").get(),System.getProperty("user.country"));
- assertEquals(Environment.current().get("user.country").get(), System.getProperty("user.country"));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java b/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
index 2276a58..bdda4d1 100644
--- a/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
+++ b/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
@@ -50,7 +50,7 @@ public class MutableTestConfigProvider implements ConfigurationProviderSpi{
dataMap.put("sons.2", "Luke");
dataMap.put("sons.3", "Benjamin");
// PropertySource provider = PropertySourceBuilder.of(CONFIG_NAME).addMap(dataMap).build();
- testConfig = new MutableConfiguration(dataMap, MetaInfo.of(CONFIG_NAME));
+ testConfig = new MutableConfiguration(dataMap, CONFIG_NAME);
}
@Override
@@ -76,13 +76,13 @@ public class MutableTestConfigProvider implements ConfigurationProviderSpi{
private static final long serialVersionUID = 8811989470609598218L;
private final Map<String,String> data = new ConcurrentHashMap<>();
- MutableConfiguration(Map<String,String> data, MetaInfo metaInfo){
- super(metaInfo);
+ MutableConfiguration(Map<String,String> data, String name){
+ super(name);
this.data.putAll(data);
}
@Override
- public Map<String, String> toMap() {
+ public Map<String, String> getProperties() {
return Collections.unmodifiableMap(data);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/java/org/apache/tamaya/internal/TestEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/internal/TestEnvironmentProvider.java b/core/src/test/java/org/apache/tamaya/internal/TestEnvironmentProvider.java
deleted file mode 100644
index d1a6c3d..0000000
--- a/core/src/test/java/org/apache/tamaya/internal/TestEnvironmentProvider.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.internal;
-
-import org.apache.tamaya.core.spi.EnvironmentProvider;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Environment provider used by some tests.
- */
-public class TestEnvironmentProvider implements EnvironmentProvider {
- private Map<String, String> data = new HashMap<>();
-
- public TestEnvironmentProvider(){
- data.put("user.country", System.getProperty("user.country"));
- data.put("java.version", System.getProperty("java.version"));
- data = Collections.unmodifiableMap(data);
- }
-
- @Override
- public boolean isActive() {
- return true;
- }
-
- @Override
- public Map<String, String> getEnvironmentData() {
- return data;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredClass.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredClass.java b/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredClass.java
new file mode 100644
index 0000000..f18271a
--- /dev/null
+++ b/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredClass.java
@@ -0,0 +1,91 @@
+/*
+ * 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.samples.annotations;
+
+import org.apache.tamaya.annotation.DefaultValue;
+import org.apache.tamaya.annotation.NoConfig;
+import org.apache.tamaya.annotation.ObservesConfigChange;
+
+import java.beans.PropertyChangeEvent;
+import java.math.BigDecimal;
+
+/**
+ * Test example of a configured tyü that is using default config key resolution.
+ */
+public class AutoConfiguredClass {
+
+ private String testProperty;
+
+ @DefaultValue("The current \\${JAVA_HOME} env property is ${env:JAVA_HOME}.")
+ String value1;
+
+ @NoConfig
+ private String value2;
+
+ @DefaultValue("N/A")
+ private String runtimeVersion;
+
+ @DefaultValue("${java.version}")
+ private String javaVersion2;
+
+ @DefaultValue("5")
+ private Integer int1;
+
+ private int int2;
+
+ @ObservesConfigChange
+ public void changeListener1(PropertyChangeEvent configChange){
+ // will be called
+ }
+
+ public String getTestProperty() {
+ return testProperty;
+ }
+
+ public String getValue1() {
+ return value1;
+ }
+
+ public String getValue2() {
+ return value2;
+ }
+
+ public String getRuntimeVersion() {
+ return runtimeVersion;
+ }
+
+ public String getJavaVersion2() {
+ return javaVersion2;
+ }
+
+ public Integer getInt1() {
+ return int1;
+ }
+
+ public int getInt2() {
+ return int2;
+ }
+
+ public String toString(){
+ return super.toString() + ": testProperty="+testProperty+", value1="+value1+", value2="+value2
+ +", int1="+int1+", int2="+int2
+ +", runtimeVersion="+runtimeVersion+", javaVersion2="+javaVersion2;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredTest.java b/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredTest.java
new file mode 100644
index 0000000..2e29cff
--- /dev/null
+++ b/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.samples.annotations;
+
+import jdk.nashorn.internal.runtime.regexp.joni.Config;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.core.config.ConfigurationBuilder;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assume.assumeTrue;
+
+/**
+ * Created by Anatole on 08.09.2014.
+ */
+public class AutoConfiguredTest {
+
+
+ @Test
+ public void testTemplateWithEnvironmentVariableOnUnixoidSystem(){
+ AutoConfiguredClass config = new AutoConfiguredClass();
+ Configuration.configure(config, ConfigurationBuilder.of("default").addPaths("classpath:cfg/autoloaded.xml").build());
+ System.out.println(config);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java b/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
index b55f731..499017a 100644
--- a/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
+++ b/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
@@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.tamaya.Configuration;
+import org.apache.tamaya.core.config.ConfigFunctions;
import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.junit.Test;
@@ -50,13 +51,13 @@ public class SimplePropertiesAndCLISample {
"classpath:test.properties").addPaths("classpath:cfg/test.xml")
.addArgs(new String[]{"-arg1", "--fullarg", "fullValue", "-myflag"}).addMap(cfgMap)
.build().toConfiguration();
- System.out.println(config.getAreas());
+ System.out.println(config.query(ConfigFunctions.getAreas()));
System.out.println("---");
- System.out.println(config.getAreas(s -> s.startsWith("another")));
+ System.out.println(config.query(ConfigFunctions.getAreas(s -> s.startsWith("another"))));
System.out.println("---");
- System.out.println(config.getTransitiveAreas());
+ System.out.println(config.query(ConfigFunctions.getTransitiveAreas()));
System.out.println("---");
- System.out.println(config.getTransitiveAreas(s -> s.startsWith("another")));
+ System.out.println(config.query(ConfigFunctions.getTransitiveAreas(s -> s.startsWith("another"))));
System.out.println("---");
System.out.println(config);
System.out.print("--- b=");
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java b/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
index 80ec280..7571c1e 100644
--- a/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
+++ b/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
@@ -43,7 +43,7 @@ import org.junit.Test;
* <li>access a keys by key (+get+)</li>
* <li>check if a keys is present (+containsKey+)</li>
* <li>get a set current all defined keys (+keySet+)</li>
- * <li>a property provider must be convertible to a +Map+, by calling +toMap()+</li>
+ * <li>a property provider must be convertible to a +Map+, by calling +getProperties()+</li>
* <li>a property provider must get access to its meta information.</li>
* </ul>
* Additionally there are other requirement important for ease current use:
@@ -74,7 +74,7 @@ public class UC1ReadProperties {
System.out.println(areaConfig2);
// iterator over an area, using streams only
- Map<String, String> areaMap = config.toMap().entrySet().stream()
+ Map<String, String> areaMap = config.getProperties().entrySet().stream()
.filter((e) -> e.getKey().startsWith("num."))
.collect(Collectors.toMap((e) -> e.getKey().substring("num.".length()), Map.Entry::getValue));
Configuration areaConfig = PropertySourceBuilder.of("Test").addMap(areaMap).build().toConfiguration();
@@ -87,7 +87,7 @@ public class UC1ReadProperties {
Configuration config = provider.toConfiguration();
assertNotNull(config);
assertTrue(config.isEmpty());
- assertTrue(config.keySet().isEmpty());
+ assertTrue(config.getProperties().isEmpty());
assertFalse(config.isMutable());
}
@@ -96,7 +96,7 @@ public class UC1ReadProperties {
PropertySource provider = PropertySourceBuilder.of("Test").addPaths("classpath:barFoo.properties").build();
assertNotNull(provider);
assertTrue(provider.isEmpty());
- assertTrue(provider.keySet().isEmpty());
+ assertTrue(provider.getProperties().isEmpty());
assertFalse(provider.isMutable());
}
@@ -155,7 +155,7 @@ public class UC1ReadProperties {
assertEquals(provider.get("a.b.b").get(), "abbValue-fromIni");
assertEquals(provider.get("a.b.a").get(), "abaValue-fromIni");
// fromMap properties
- assertTrue(provider.containsKey("num.BD"));
+ assertTrue(provider.get("num.BD").isPresent());
// fromMap xml properties
assertEquals(provider.get("a-xml").get(), "aFromXml");
assertEquals(provider.get("b-xml").get(), "bFromXml");
@@ -164,8 +164,8 @@ public class UC1ReadProperties {
@Test
public void checkForAValue() {
PropertySource provider = PropertySourceBuilder.of("Test").addPaths("classpath:ucs/UC1ReadProperties/UC1ReadPropertiesTest.properties").build();
- assertFalse(provider.containsKey("blabla"));
- assertTrue(provider.containsKey("num.BD"));
+ assertFalse(provider.get("blabla").isPresent());
+ assertTrue(provider.get("num.BD").isPresent());
assertFalse(provider.get("blabla").isPresent());
assertTrue(provider.get("num.BD").isPresent());
}
@@ -173,18 +173,18 @@ public class UC1ReadProperties {
@Test
public void checkKeys() {
PropertySource provider = PropertySourceBuilder.of("Test").addPaths("classpath:ucs/UC1ReadProperties/UC1ReadPropertiesTest.properties").build();
- assertEquals(provider.keySet().size(), 16);
- assertTrue(provider.keySet().contains("boolean"));
- assertFalse(provider.keySet().contains("blabla"));
+ assertEquals(provider.getProperties().size(), 16);
+ assertTrue(provider.getProperties().keySet().contains("boolean"));
+ assertFalse(provider.getProperties().keySet().contains("blabla"));
}
@Test
public void checkToMap() {
PropertySource provider = PropertySourceBuilder.of("Test").addPaths("classpath:ucs/UC1ReadProperties/UC1ReadPropertiesTest.properties").build();
- Map<String, String> map = provider.toMap();
+ Map<String, String> map = provider.getProperties();
assertNotNull(map);
assertEquals(map.size(), 16);
- assertEquals(provider.keySet(), map.keySet());
+ assertEquals(provider.getProperties().keySet(), map.keySet());
assertTrue(map.keySet().contains("boolean"));
assertFalse(map.keySet().contains("blabla"));
}
@@ -192,8 +192,7 @@ public class UC1ReadProperties {
@Test
public void checkMetaInfo() {
PropertySource provider = PropertySourceBuilder.of("Test").addPaths("classpath:ucs/UC1ReadProperties/UC1ReadPropertiesTest.properties").build();
- MetaInfo meta = provider.getMetaInfo();
- assertNotNull(meta);
+ assertNotNull(provider.getName());
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java b/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
index ba522a7..3a6e471 100644
--- a/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
+++ b/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
@@ -62,7 +62,7 @@ public class UC2CombineProperties {
public void dynamicAggregationTests() {
PropertySource props1 = PropertySourceBuilder.of().addPaths("classpath:ucs/UC2CombineProperties/props1.properties").build();
PropertySource props2 = PropertySourceBuilder.of().addPaths("classpath:ucs/UC2CombineProperties/props2.properties").build();
- PropertySource props = PropertySourceBuilder.of().withAggregationPolicy((k, v1, v2) -> (v1 != null ? v1 : "") + '[' + v2 + "]").withMetaInfo(MetaInfo.of("dynamicAggregationTests"))
+ PropertySource props = PropertySourceBuilder.of().withAggregationPolicy((k, v1, v2) -> (v1 != null ? v1 : "") + '[' + v2 + "]").withName("dynamicAggregationTests")
.aggregate(props1, props2).build();
System.out.println(props);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.EnvironmentProvider
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.EnvironmentProvider b/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.EnvironmentProvider
index d35127f..74382e7 100644
--- a/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.EnvironmentProvider
+++ b/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.EnvironmentProvider
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.internal.TestEnvironmentProvider
\ No newline at end of file
+org.apache.tamaya.metamodel.environment.TestEnvironmentProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/resources/cfg/autoloaded.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/cfg/autoloaded.xml b/core/src/test/resources/cfg/autoloaded.xml
new file mode 100644
index 0000000..b64cb76
--- /dev/null
+++ b/core/src/test/resources/cfg/autoloaded.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
+<properties version="1.0">
+ <entry key="testFromXml">testValue</entry>
+ <entry key="b">Bill</entry>
+ <entry key="a.compound.area.entry">myCompundAreaVlaueFromXml</entry>
+ <entry key="an.area.entry">myCompundAreaVlaueFromXml2</entry>
+ <!-- DirectMapping test -->
+ <entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.value1">This \${JAVA_HOME} is cool!</entry>
+ <entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.value2">Should not be set because @NoConfig !</entry>
+ <entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.testProperty">a test property value</entry>
+ <entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.runtimeVersion">my RT 1-0-0--build-1234</entry>
+ <entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.int1">1</entry>
+ <entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.int2">22</entry>
+</properties>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/test/resources/cfg/test.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/cfg/test.xml b/core/src/test/resources/cfg/test.xml
index fc65101..b64cb76 100644
--- a/core/src/test/resources/cfg/test.xml
+++ b/core/src/test/resources/cfg/test.xml
@@ -23,4 +23,11 @@ under the License.
<entry key="b">Bill</entry>
<entry key="a.compound.area.entry">myCompundAreaVlaueFromXml</entry>
<entry key="an.area.entry">myCompundAreaVlaueFromXml2</entry>
+ <!-- DirectMapping test -->
+ <entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.value1">This \${JAVA_HOME} is cool!</entry>
+ <entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.value2">Should not be set because @NoConfig !</entry>
+ <entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.testProperty">a test property value</entry>
+ <entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.runtimeVersion">my RT 1-0-0--build-1234</entry>
+ <entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.int1">1</entry>
+ <entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.int2">22</entry>
</properties>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedConfig.java
----------------------------------------------------------------------
diff --git a/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedConfig.java b/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedConfig.java
index 681c02b..b991690 100644
--- a/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedConfig.java
+++ b/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedConfig.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.management;
+package org.apache.tamaya.se;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.AggregationPolicy;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedConfigMBean.java
----------------------------------------------------------------------
diff --git a/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedConfigMBean.java b/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedConfigMBean.java
index 381d43a..c2ade13 100644
--- a/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedConfigMBean.java
+++ b/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedConfigMBean.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.management;
+package org.apache.tamaya.se;
import org.apache.tamaya.ConfigException;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedEnvironment.java
----------------------------------------------------------------------
diff --git a/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedEnvironment.java b/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedEnvironment.java
index 7caff90..e85b1c1 100644
--- a/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedEnvironment.java
+++ b/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedEnvironment.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.management;
+package org.apache.tamaya.se;
import org.apache.tamaya.Environment;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedEnvironmentMBean.java
----------------------------------------------------------------------
diff --git a/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedEnvironmentMBean.java b/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedEnvironmentMBean.java
index 5d86700..ef3b861 100644
--- a/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedEnvironmentMBean.java
+++ b/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedEnvironmentMBean.java
@@ -16,12 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.management;
+package org.apache.tamaya.se;
import java.util.List;
import java.util.Map;
-import java.util.Set;
/**
* Managed bean interface for accessing environment data.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/integration/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/pom.xml b/modules/integration/pom.xml
index 44d1a43..95f2b07 100644
--- a/modules/integration/pom.xml
+++ b/modules/integration/pom.xml
@@ -1,45 +1,20 @@
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy current the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<?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">
- <modelVersion>4.0.0</modelVersion>
-
<parent>
- <groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-ext-all</artifactId>
+ <groupId>org.apache.tamaya.ext</groupId>
<version>0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
- <groupId>org.apache.tamaya.integration</groupId>
- <artifactId>tamaya-integration-all</artifactId>
- <name>Apache Tamaya Modules Integration</name>
- <packaging>pom</packaging>
+ <modelVersion>4.0.0</modelVersion>
- <properties>
- <github.global.server>github</github.global.server>
- <jdkVersion>1.8</jdkVersion>
- <maven.compile.targetLevel>${jdkVersion}</maven.compile.targetLevel>
- <maven.compile.sourceLevel>${jdkVersion}</maven.compile.sourceLevel>
- </properties>
+ <artifactId>org.apache.tamaya.metamodels.environment</artifactId>
<modules>
<module>cdi</module>
+ <module>se</module>
</modules>
-</project>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/integration/se/src/main/java/org/apache/tamaya/integration/se/ConfiguredSystemProperties.java
----------------------------------------------------------------------
diff --git a/modules/integration/se/src/main/java/org/apache/tamaya/integration/se/ConfiguredSystemProperties.java b/modules/integration/se/src/main/java/org/apache/tamaya/integration/se/ConfiguredSystemProperties.java
new file mode 100644
index 0000000..cdef5be
--- /dev/null
+++ b/modules/integration/se/src/main/java/org/apache/tamaya/integration/se/ConfiguredSystemProperties.java
@@ -0,0 +1,353 @@
+/*
+ * 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.integration.se;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.BiConsumer;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import java.util.logging.Logger;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.Environment;
+
+/**
+ * Properties implementation class that can be applied as current System properties by calling
+ * {@link ConfiguredSystemProperties#install()}. The system properties will
+ * then behave contextually depending on the current runtime configuration active.
+ */
+public class ConfiguredSystemProperties extends Properties {
+
+ private static final long serialVersionUID = 2152870929299226804L;
+
+ private static final Logger LOG = Logger.getLogger(ConfiguredSystemProperties.class.getName());
+ private Properties initialProperties;
+ private static volatile Map<String, Properties> contextualProperties = new ConcurrentHashMap<>();
+ private static volatile Supplier<String> contextProvider = () ->
+ Environment.current().get("context.id").orElse("<system>");
+
+
+ private final Object LOCK = new Object();
+
+
+ private ConfiguredSystemProperties(Properties initialProperties) {
+ super(initialProperties);
+ this.initialProperties = initialProperties;
+ }
+
+ public static void install() {
+ Properties props = System.getProperties();
+ if (props instanceof ConfiguredSystemProperties) {
+ return;
+ }
+ ConfiguredSystemProperties systemProps = new ConfiguredSystemProperties(props);
+ LOG.finest("Installing enhanced system properties...");
+ System.setProperties(systemProps);
+ LOG.info("Installed enhanced system properties successfully.");
+ }
+
+ public static void uninstall() {
+ Properties props = System.getProperties();
+ if (props instanceof ConfiguredSystemProperties) {
+ Properties initialProperties = ((ConfiguredSystemProperties) props).initialProperties;
+ LOG.finest("Uninstalling enhanced system properties...");
+ System.setProperties(initialProperties);
+ LOG.info("Uninstalled enhanced system properties successfully.");
+ }
+ }
+
+ @Override
+ public String getProperty(String key) {
+ return getContextualProperties().getProperty(key);
+ }
+
+ @Override
+ public String getProperty(String key, String defaultValue) {
+ return getContextualProperties().getProperty(key, defaultValue);
+ }
+
+ @Override
+ public Enumeration<?> propertyNames() {
+ return getContextualProperties().propertyNames();
+ }
+
+ @Override
+ public Set<String> stringPropertyNames() {
+ return getContextualProperties().stringPropertyNames();
+ }
+
+ @Override
+ public synchronized int size() {
+ return getContextualProperties().size();
+ }
+
+ @Override
+ public synchronized Enumeration<Object> keys() {
+ return getContextualProperties().keys();
+ }
+
+ @Override
+ public synchronized Enumeration<Object> elements() {
+ return getContextualProperties().elements();
+ }
+
+ @Override
+ public synchronized boolean contains(Object value) {
+ return getContextualProperties().contains(value);
+ }
+
+ @Override
+ public boolean containsValue(Object value) {
+ return getContextualProperties().containsValue(value);
+ }
+
+ @Override
+ public synchronized boolean containsKey(Object key) {
+ return getContextualProperties().containsKey(key);
+ }
+
+ @Override
+ public synchronized Object get(Object key) {
+ return getContextualProperties().get(key);
+ }
+
+ @Override
+ public synchronized Object clone() {
+ return getContextualProperties().clone();
+ }
+
+ @Override
+ public Set<Object> keySet() {
+ return getContextualProperties().keySet();
+ }
+
+ @Override
+ public Set<Map.Entry<Object, Object>> entrySet() {
+ return getContextualProperties().entrySet();
+ }
+
+ @Override
+ public Collection<Object> values() {
+ return getContextualProperties().values();
+ }
+
+
+ @Override
+ public Object getOrDefault(Object key, Object defaultValue) {
+ return getContextualProperties().getOrDefault(key, defaultValue);
+ }
+
+ @Override
+ public void forEach(BiConsumer<? super Object, ? super Object> action) {
+ getContextualProperties().forEach(action);
+ }
+
+
+ @Override
+ public Object computeIfAbsent(Object key, Function<? super Object, ?> mappingFunction) {
+ return getContextualProperties().computeIfAbsent(key, mappingFunction);
+ }
+
+ @Override
+ public synchronized Object computeIfPresent(Object key, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
+ return getContextualProperties().computeIfPresent(key, remappingFunction);
+ }
+
+ @Override
+ public synchronized Object compute(Object key, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
+ return getContextualProperties().compute(key, remappingFunction);
+ }
+
+ @Override
+ public String toString() {
+ return getContextualProperties().toString();
+ }
+
+ @Override
+ public synchronized Object setProperty(String key, String value) {
+ return getContextualProperties().setProperty(key, value);
+ }
+
+ @Override
+ public synchronized void load(Reader reader) throws IOException {
+ getContextualProperties().load(reader);
+ }
+
+ @Override
+ public synchronized void load(InputStream inStream) throws IOException {
+ getContextualProperties().load(inStream);
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public void save(OutputStream out, String comments) {
+ super.save(out, comments);
+ }
+
+ @Override
+ public void store(Writer writer, String comments) throws IOException {
+ getContextualProperties().store(writer, comments);
+ }
+
+ @Override
+ public void store(OutputStream out, String comments) throws IOException {
+ getContextualProperties().store(out, comments);
+ }
+
+ @Override
+ public void loadFromXML(InputStream in) throws IOException {
+ getContextualProperties().loadFromXML(in);
+ }
+
+ @Override
+ public void storeToXML(OutputStream os, String comment) throws IOException {
+ getContextualProperties().storeToXML(os, comment);
+ }
+
+ @Override
+ public void storeToXML(OutputStream os, String comment, String encoding) throws IOException {
+ getContextualProperties().storeToXML(os, comment, encoding);
+ }
+
+ @Override
+ public void list(PrintStream out) {
+ getContextualProperties().list(out);
+ }
+
+ @Override
+ public void list(PrintWriter out) {
+ getContextualProperties().list(out);
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return getContextualProperties().isEmpty();
+ }
+
+ @Override
+ public Object put(Object key, Object value) {
+ return getContextualProperties().put(key, value);
+ }
+
+ @Override
+ public Object remove(Object key) {
+ return getContextualProperties().remove(key);
+ }
+
+ @Override
+ public void putAll(Map<?, ?> t) {
+ getContextualProperties().putAll(t);
+ }
+
+ @Override
+ public void clear() {
+ getContextualProperties().clear();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return getContextualProperties().equals(o);
+ }
+
+ @Override
+ public int hashCode() {
+ return getContextualProperties().hashCode();
+ }
+
+ @Override
+ public void replaceAll(BiFunction<? super Object, ? super Object, ?> function) {
+ getContextualProperties().replaceAll(function);
+ }
+
+ @Override
+ public Object putIfAbsent(Object key, Object value) {
+ return getContextualProperties().putIfAbsent(key, value);
+ }
+
+ @Override
+ public boolean remove(Object key, Object value) {
+ return getContextualProperties().remove(key, value);
+ }
+
+ @Override
+ public boolean replace(Object key, Object oldValue, Object newValue) {
+ return getContextualProperties().replace(key, oldValue, newValue);
+ }
+
+ @Override
+ public Object replace(Object key, Object value) {
+ return getContextualProperties().replace(key, value);
+ }
+
+ @Override
+ public Object merge(Object key, Object value, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
+ return getContextualProperties().merge(key, value, remappingFunction);
+ }
+
+ public Properties getInitialProperties() {
+ return initialProperties;
+ }
+
+ /**
+ * Uninstalls the contextual system properties for the current context, as determined by the current
+ * context provider active.
+ */
+ public static void resetProperties() {
+ String contextId = contextProvider == null ? "" : contextProvider.get();
+ contextualProperties.remove(contextId);
+ }
+
+ protected Properties getContextualProperties() {
+ String contextId = contextProvider == null ? "" : contextProvider.get();
+ Properties props = ConfiguredSystemProperties.contextualProperties.get(contextId);
+ if (props == null) {
+ synchronized (LOCK) {
+ props = ConfiguredSystemProperties.contextualProperties.get(contextId);
+ if (props == null) {
+ props = createNewProperties();
+ contextualProperties.put(contextId, props);
+ }
+ }
+ }
+ return props;
+ }
+
+ protected Properties createNewProperties() {
+ Properties props = new Properties(initialProperties);
+ Configuration config = Configuration.current();
+ Map<String, String> configMap = config.getProperties();
+ for (Map.Entry<String, String> en : configMap.entrySet()) {
+ props.put(en.getKey(), en.getValue());
+ }
+ return props;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/BuildableEnvironment.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/BuildableEnvironment.java b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/BuildableEnvironment.java
new file mode 100644
index 0000000..3633c97
--- /dev/null
+++ b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/BuildableEnvironment.java
@@ -0,0 +1,109 @@
+/*
+ * 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.environment;
+
+import java.util.*;
+
+/**
+ * Environment class that is used by the {@link org.apache.tamaya.metamodel.environment.EnvironmentBuilder}.
+ */
+class BuildableEnvironment implements Environment {
+
+ /** The environment data. */
+ private Map<String,String> context = new TreeMap<>();
+
+ /**
+ * Constructor.
+ * @param builder the builder, not null.
+ */
+ BuildableEnvironment(EnvironmentBuilder builder){
+ Objects.requireNonNull(builder);
+ context.putAll(builder.contextData);
+ }
+
+ @Override
+ public Map<String, String> toMap() {
+ return context;
+ }
+
+ @Override
+ public Optional<String> get(String key){
+ return Optional.ofNullable(context.get(key));
+ }
+
+ @Override
+ public boolean containsKey(String key){
+ return context.containsKey(key);
+ }
+
+ @Override
+ public Set<String> keySet() {
+ return context.keySet();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ BuildableEnvironment that = (BuildableEnvironment) o;
+ return context.equals(that.context);
+ }
+
+ @Override
+ public int hashCode() {
+ return context.hashCode();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString(){
+ return "Environment: " + getData();
+ }
+
+ /**
+ * Get the delta.
+ * @return
+ */
+ private String getData() {
+ StringBuilder b = new StringBuilder();
+ for(Map.Entry<String,String> en: this.context.entrySet()){
+ b.append(" ").append(en.getKey()).append('=').append(escape(en.getValue())).append('\n');
+ }
+ if(b.length()>0)
+ b.setLength(b.length()-1);
+ return b.toString();
+ }
+
+ /**
+ * Escapes several characters.
+ * @param value
+ * @return
+ */
+ private String escape(String value){
+ if(value==null)
+ return null;
+ return value.replaceAll("\n", "\\\\n").replaceAll("\r", "\\\\r").replaceAll("\t", "\\\\t")
+ .replaceAll("=", "\\\\=");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/Environment.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/Environment.java b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/Environment.java
new file mode 100644
index 0000000..8a8b157
--- /dev/null
+++ b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/Environment.java
@@ -0,0 +1,86 @@
+/*
+ * 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.environment;
+
+import org.apache.tamaya.metamodel.environment.spi.EnvironmentSpi;
+import org.apache.tamaya.spi.ServiceContext;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * Models a runtime environment. Instances current this class are used to
+ * evaluate the correct configuration artifacts.<br/>
+ * <h3>Implementation Requirements</h3>
+ * <p>
+ * Implementations current this interface must be
+ * <ul>
+ * <li>Thread safe.
+ * <li>Immutable
+ * <li>serializable
+ * </ul>
+ */
+public interface Environment{
+
+ /**
+ * Access a property.
+ * @param key the property's key, not null.
+ * @return the property's keys.
+ */
+ Optional<String> get(String key);
+
+ /**
+ * Checks if a property is defined.
+ * @param key the property's key, not null.
+ * @return true, if the property is existing.
+ */
+ boolean containsKey(String key);
+
+ /**
+ * Access the set current property keys, defined by this provider.
+ * @return the key set, never null.
+ */
+ Set<String> keySet();
+
+ /**
+ * Access the environment as Map.
+ * @return the Map instance containing the environments properties, never null.
+ */
+ Map<String,String> toMap();
+
+ /**
+ * Get the current {@link org.apache.tamaya.metamodel.environment.Environment}. The environment is used to determine the current runtime state, which
+ * is important for returning the correct configuration.
+ * @return the current Environment, never null.
+ */
+ public static Environment current(){
+ return ServiceContext.getInstance().getSingleton(EnvironmentSpi.class).getCurrentEnvironment();
+ }
+
+ /**
+ * Get the current {@link Environment}. The environment is used to determine the current runtime state, which
+ * is important for returning the correct configuration.
+ * @return the current Environment, never null.
+ */
+ public static Environment root(){
+ return ServiceContext.getInstance().getSingleton(EnvironmentSpi.class).getRootEnvironment();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/EnvironmentBuilder.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/EnvironmentBuilder.java b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/EnvironmentBuilder.java
new file mode 100644
index 0000000..17ec34b
--- /dev/null
+++ b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/EnvironmentBuilder.java
@@ -0,0 +1,97 @@
+/*
+ * 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.environment;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+* Builder to create new {@link Environment instances.}
+*/
+public final class EnvironmentBuilder{
+
+ /** The property name for the stage property. */
+ public static final String STAGE_PROP = "stage";
+
+ /** THe environment data. */
+ Map<String,String> contextData = new HashMap<>();
+
+ /**
+ * Constructor.
+ */
+ private EnvironmentBuilder() {
+ }
+
+ /**
+ * Creates a new buildr instance.
+ * @return the new builder instance.
+ */
+ public static final EnvironmentBuilder of() {
+ return new EnvironmentBuilder();
+ }
+
+ /**
+ * Sets a new environment property.
+ * @param key the key, not null.
+ * @param value the keys, not null.
+ * @return the builder for chaining
+ */
+ public EnvironmentBuilder set(String key, String value){
+ this.contextData.put(key, value);
+ return this;
+ }
+
+ /**
+ * Sets new environment properties.
+ * @param values the key/values, not null.
+ * @return the builder for chaining
+ */
+ public EnvironmentBuilder setAll(Map<String,String> values){
+ this.contextData.putAll(values);
+ return this;
+ }
+
+ /**
+ * Sets the stage using the default stage key.
+ * @param stage The stage, not null.
+ * @return the builder for chaining.
+ */
+ public EnvironmentBuilder setStage(String stage){
+ this.contextData.put(STAGE_PROP, Objects.requireNonNull(stage));
+ return this;
+ }
+
+ /**
+ * Access a property
+ * @param key the key, not null.
+ * @return the builder for chaining.
+ */
+ public String getProperty(String key) {
+ return this.contextData.get(key);
+ }
+
+ /**
+ * Builds a new Environment.
+ * @return a new Environment, never null.
+ */
+ public Environment build() {
+ return new BuildableEnvironment(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java
new file mode 100644
index 0000000..e2d1759
--- /dev/null
+++ b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java
@@ -0,0 +1,101 @@
+/*
+ * 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.environment.internal;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tamaya.core.config.ConfigurationFormats;
+import org.apache.tamaya.core.resource.Resource;
+import org.apache.tamaya.core.resource.ResourceLoader;
+import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
+import org.apache.tamaya.spi.ServiceContext;
+
+/**
+ * Application environment provider that is dependent on the current context classloader and tries to
+ * evaluate {@code META-INF/env/application.properties, META-INF/env/application.xml and META-INF/env/application.ini}.
+ * Only if a property named {@code org.apache.tamaya.env.applicationId} is found, it will
+ * be used as the {@code environmentId} and a corresponding {@link org.apache.tamaya.metamodel.environment.Environment} instance
+ * is created and attached.
+ */
+public class ClassLoaderDependentApplicationEnvironmentProvider implements EnvironmentProvider {
+
+ private static final Logger LOG = Logger.getLogger(ClassLoaderDependentApplicationEnvironmentProvider.class.getName());
+
+ private Map<ClassLoader, Map<String,String>> environments = new ConcurrentHashMap<>();
+ private Map<ClassLoader, Boolean> environmentAvailable = new ConcurrentHashMap<>();
+
+ @Override
+ public boolean isActive() {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if(cl==null){
+ return false;
+ }
+ Boolean available = this.environmentAvailable.get(cl);
+ if(available!=null && !available){
+ return false;
+ }
+ List<Resource> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
+ "classpath:META-INF/env/application.properties", "classpath:META-INF/env/application.xml", "classpath:META-INF/env/application.ini");
+ available = !propertyUris.isEmpty();
+ this.environmentAvailable.put(cl, available);
+ return available;
+ }
+
+ @Override
+ public Map<String,String> getEnvironmentData() {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if(cl==null){
+ return null;
+ }
+ Map<String,String> data = this.environments.get(cl);
+ if(data!=null){
+ return data;
+ }
+ List<Resource> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
+ "classpath:META-INF/env/application.properties", "classpath:META-INF/env/application.xml", "classpath:META-INF/env/application.ini");
+ data = new HashMap<>();
+
+ for(Resource resource:propertyUris){
+ try{
+ ConfigurationFormat format = ConfigurationFormats.getFormat(resource);
+ data.putAll(format.readConfiguration(resource));
+ }
+ catch(Exception e){
+ LOG.log(Level.SEVERE, e, () -> "Error reading application environment data fromMap " + resource);
+ }
+ }
+ data.put("classloader.type", cl.getClass().getName());
+ data.put("classloader.info", cl.toString());
+ Set<Resource> uris = new HashSet<>();
+ uris.addAll(propertyUris);
+ data.put("environment.sources", uris.toString());
+ data = Collections.unmodifiableMap(data);
+ this.environments.put(cl, data);
+ return data;
+ }
+}
[3/6] incubator-tamaya git commit: TAMAYA-19: - Moved out much of
unused/experimental code. - Reduced API (removing package private singletons)
- Aligned PropertySource with Deltaspike (mostly). - Moved Environment model
to separate metamodel module.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/IntersectingPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/IntersectingPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/IntersectingPropertySource.java
index bc22822..d7c46d2 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/IntersectingPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/IntersectingPropertySource.java
@@ -34,33 +34,21 @@ class IntersectingPropertySource extends AbstractPropertySource {
private List<PropertySource> providers;
private PropertySource aggregatedDelegate;
- public IntersectingPropertySource(MetaInfo metaInfo, AggregationPolicy policy, List<PropertySource> providers) {
- super(MetaInfoBuilder.of(metaInfo).setType("intersection").build());
+ public IntersectingPropertySource(String name, AggregationPolicy policy, List<PropertySource> providers) {
+ super(name);
this.providers = new ArrayList<>(providers);
- aggregatedDelegate = PropertySourceBuilder.of(getMetaInfo()).withAggregationPolicy(policy)
+ aggregatedDelegate = PropertySourceBuilder.of(name).withAggregationPolicy(policy)
.addProviders(this.providers).build();
}
@Override
public Optional<String> get(String key) {
- if (containsKey(key))
- return aggregatedDelegate.get(key);
- return Optional.empty();
+ return aggregatedDelegate.get(key);
}
@Override
- public boolean containsKey(String key) {
- for (PropertySource prov : this.providers) {
- if (!prov.containsKey(key)) {
- return false;
- }
- }
- return true;
- }
-
- @Override
- public Map<String, String> toMap() {
- return aggregatedDelegate.toMap().entrySet().stream().filter(en -> containsKey(en.getKey())).collect(
+ public Map<String, String> getProperties() {
+ return aggregatedDelegate.getProperties().entrySet().stream().filter(en -> get(en.getKey()).isPresent()).collect(
Collectors.toConcurrentMap(Map.Entry::getKey, Map.Entry::getValue));
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/MapBasedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/MapBasedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/MapBasedPropertySource.java
index 9f2e90c..d4c8968 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/MapBasedPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/MapBasedPropertySource.java
@@ -44,8 +44,8 @@ class MapBasedPropertySource extends AbstractPropertySource {
*
* @param entries the config entries, not null.
*/
- MapBasedPropertySource(MetaInfo metaInfo, Map<String, String> entries){
- super(metaInfo);
+ MapBasedPropertySource(String name, Map<String, String> entries){
+ super(name);
Objects.requireNonNull(entries, "entries required.");
this.entries.putAll(entries);
}
@@ -58,21 +58,21 @@ class MapBasedPropertySource extends AbstractPropertySource {
* @param sources the sources
* @param errors the errors
*/
- MapBasedPropertySource(MetaInfo metaInfo, Map<String, String> entries, Set<String> sources,
+ MapBasedPropertySource(String name, Map<String, String> entries, Set<String> sources,
Collection<Throwable> errors){
- super(metaInfo);
+ super(name);
Objects.requireNonNull(entries, "entries required.");
this.entries.putAll(entries);
addSources(sources);
}
- MapBasedPropertySource(MetaInfo metaInfo, Set<String> sources){
- super(metaInfo);
+ MapBasedPropertySource(String name, Set<String> sources){
+ super(name);
addSources(sources);
}
@Override
- public Map<String, String> toMap() {
+ public Map<String, String> getProperties() {
return new HashMap<>(this.entries);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java
index 4ea663a..56426ca 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java
@@ -19,10 +19,9 @@
package org.apache.tamaya.core.properties;
import org.apache.tamaya.*;
-import org.apache.tamaya.core.config.ConfigurationFormats;
import org.apache.tamaya.core.resource.Resource;
import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.core.spi.ConfigurationFormat;
+import org.apache.tamaya.core.config.ConfigurationFormat;
import org.apache.tamaya.core.resource.ResourceLoader;
import java.util.*;
@@ -37,15 +36,15 @@ final class PathBasedPropertySource extends AbstractPropertySource {
private Map<String, String> properties = new HashMap<>();
private AggregationPolicy aggregationPolicy;
- public PathBasedPropertySource(MetaInfo metaInfo, Collection<String> paths, AggregationPolicy aggregationPolicy) {
- super(metaInfo);
+ public PathBasedPropertySource(String name, Collection<String> paths, AggregationPolicy aggregationPolicy) {
+ super(name);
this.paths.addAll(Objects.requireNonNull(paths));
this.aggregationPolicy = Objects.requireNonNull(aggregationPolicy);
init();
}
@Override
- public Map<String, String> toMap() {
+ public Map<String, String> getProperties() {
return this.properties;
}
@@ -55,7 +54,7 @@ final class PathBasedPropertySource extends AbstractPropertySource {
paths.forEach((path) -> {
effectivePaths.add(path);
for (Resource res : ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(path)) {
- ConfigurationFormat format = ConfigurationFormats.getFormat(res);
+ ConfigurationFormat format = ConfigurationFormat.from(res);
if (format != null) {
try {
Map<String, String> read = format.readConfiguration(res);
@@ -78,8 +77,8 @@ final class PathBasedPropertySource extends AbstractPropertySource {
}
}
});
- metaInfo = MetaInfoBuilder.of(getMetaInfo())
- .setSourceExpressions(new String[effectivePaths.size()])
- .set("sources", sources.toString()).build();
+// metaInfo = MetaInfoBuilder.of(getMetaInfo())
+// .setSourceExpressions(new String[effectivePaths.size()])
+// .set("sources", sources.toString()).build();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceBuilder.java b/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceBuilder.java
index a2376d4..5cc93ad 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceBuilder.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceBuilder.java
@@ -27,6 +27,7 @@ import java.util.Objects;
import java.util.function.Predicate;
import java.util.function.Supplier;
+import com.oracle.webservices.internal.api.message.PropertySet;
import org.apache.tamaya.AggregationPolicy;
import org.apache.tamaya.MetaInfo;
import org.apache.tamaya.MetaInfoBuilder;
@@ -36,19 +37,16 @@ import org.apache.tamaya.PropertySource;
* Builder for assembling non trivial property providers.
*/
public final class PropertySourceBuilder {
-// private static final Supplier<IllegalStateException> noPropertyProviderAvailable =
-// () -> new IllegalStateException("No PropertyProvidersSingletonSpi available.");
-
/**
- * The final meta info to be used, or null, if a default should be generated.
+ * Name used for the final result.
*/
- private MetaInfoBuilder metaInfoBuilder;
+ private String name;
/**
- * Meta info used for the next operation.
+ * Name used for the next operation.
*/
- private MetaInfo metaInfo;
+ private String currentName;
/**
* the current property provider, or null.
@@ -62,46 +60,40 @@ public final class PropertySourceBuilder {
/**
* Private singleton constructor.
*/
- private PropertySourceBuilder(MetaInfo metaInfo) {
- this.metaInfoBuilder = MetaInfoBuilder.of(Objects.requireNonNull(metaInfo)).setInfo("Built by PropertyProviderBuilder.");
- }
-
- /**
- * Private singleton constructor.
- */
private PropertySourceBuilder(String name) {
- this.metaInfoBuilder = MetaInfoBuilder.of(name);
+ this.name = Objects.requireNonNull(name);
}
/**
* Private singleton constructor.
*/
- private PropertySourceBuilder(PropertySource provider) {
- this.metaInfoBuilder = MetaInfoBuilder.of(Objects.requireNonNull(provider).getMetaInfo());
- this.current = provider;
+ private PropertySourceBuilder(String name, PropertySource propertySource) {
+ this.name = Objects.requireNonNull(name);
+ this.current = propertySource;
}
-
/**
* Creates a new builder instance.
*
+ * @param name the provider name, not null.
* @param provider the base provider to be used, not null.
* @return a new builder instance, never null.
*/
- public static PropertySourceBuilder of(PropertySource provider) {
- return new PropertySourceBuilder(provider);
+ public static PropertySourceBuilder of(String name, PropertySource provider) {
+ return new PropertySourceBuilder(name, provider);
}
/**
* Creates a new builder instance.
*
- * @param metaInfo the meta information, not null.
+ * @param provider the base provider to be used, not null.
* @return a new builder instance, never null.
*/
- public static PropertySourceBuilder of(MetaInfo metaInfo) {
- return new PropertySourceBuilder(metaInfo);
+ public static PropertySourceBuilder of(PropertySource provider) {
+ return new PropertySourceBuilder(provider.getName(), provider);
}
+
/**
* Creates a new builder instance.
*
@@ -137,17 +129,6 @@ public final class PropertySourceBuilder {
}
/**
- * Sets the meta info to be used for the next operation.
- *
- * @param metaInfo the meta info, not null.
- * @return the builder for chaining.
- */
- public PropertySourceBuilder withMetaInfo(MetaInfo metaInfo) {
- this.metaInfo = Objects.requireNonNull(metaInfo);
- return this;
- }
-
- /**
* Adds the given providers with the current active {@link org.apache.tamaya.AggregationPolicy}. By
* default {@link org.apache.tamaya.AggregationPolicy#OVERRIDE} is used.
* @see #withAggregationPolicy(AggregationPolicy)
@@ -177,33 +158,18 @@ public final class PropertySourceBuilder {
allProviders.add(0, this.current);
}
StringBuilder b = new StringBuilder();
- providers.forEach(p -> b.append(p.getMetaInfo().toString()).append(','));
+ providers.forEach(p -> b.append(p.getName()).append(','));
b.setLength(b.length()-1);
String source = b.toString();
- MetaInfo mi = this.metaInfo;
- if (mi == null) {
- mi = MetaInfoBuilder.of("aggregate")
- .setSources(source).build();
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<aggregate> -> source=" + source;
}
- this.current = PropertySourceFactory.aggregate(mi, this.aggregationPolicy, allProviders);
-
- addProviderChainInfo(source);
- this.metaInfo = null;
+ this.current = PropertySourceFactory.aggregate(name, this.aggregationPolicy, allProviders);
+ this.currentName = null;
return this;
}
- private void addProviderChainInfo(String info){
- String providerChain = metaInfoBuilder.get("providerChain");
-
- if(providerChain == null){
- providerChain = "\n " + info;
- }
- else{
- providerChain = providerChain + ",\n " + info;
- }
- metaInfoBuilder.set("providerChain", providerChain);
- }
-
/**
* Creates a new {@link PropertySource} using the given command line arguments and adds it
* using the current aggregation policy in place.
@@ -215,11 +181,11 @@ public final class PropertySourceBuilder {
if(args.length==0){
return this;
}
- MetaInfo mi = this.metaInfo;
- if (mi == null) {
- mi = MetaInfoBuilder.of("args").build();
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<CLI-args>";
}
- PropertySource argProvider = PropertySourceFactory.fromArgs(mi, args);
+ PropertySource argProvider = PropertySourceFactory.fromArgs(name, args);
return addProviders(argProvider);
}
@@ -251,13 +217,11 @@ public final class PropertySourceBuilder {
if(paths.isEmpty()){
return this;
}
- MetaInfo mi = this.metaInfo;
- if (mi == null) {
- mi = MetaInfoBuilder.of("aggregate").set("paths", paths.toString()).build();
- } else {
- mi = MetaInfoBuilder.of(metaInfo).set("paths", paths.toString()).build();
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<aggregate> -> paths=" + paths.toString();
}
- return addProviders(PropertySourceFactory.fromPaths(mi, aggregationPolicy, paths));
+ return addProviders(PropertySourceFactory.fromPaths(name, aggregationPolicy, paths));
}
/**
@@ -285,14 +249,11 @@ public final class PropertySourceBuilder {
if(urls.isEmpty()){
return this;
}
- MetaInfo mi = this.metaInfo;
- if (mi == null) {
- mi = MetaInfoBuilder.of("aggregate").set("urls", urls.toString()).build();
- } else {
- mi = MetaInfoBuilder.of(metaInfo).set("urls", urls.toString()).build();
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<aggregate> -> urls=" + urls;
}
-
- return addProviders(PropertySourceFactory.fromURLs(mi, this.aggregationPolicy, urls));
+ return addProviders(PropertySourceFactory.fromURLs(name, this.aggregationPolicy, urls));
}
@@ -307,13 +268,11 @@ public final class PropertySourceBuilder {
if(map.isEmpty()){
return this;
}
- MetaInfo mi = this.metaInfo;
- if (mi == null) {
- mi = MetaInfoBuilder.of("map").build();
- } else {
- mi = MetaInfoBuilder.of(metaInfo).build();
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<Map> -> map=" + map;
}
- return addProviders(PropertySourceFactory.fromMap(mi, map));
+ return addProviders(PropertySourceFactory.fromMap(name, map));
}
@@ -323,13 +282,10 @@ public final class PropertySourceBuilder {
* @return the builder for chaining.
*/
public PropertySourceBuilder addEnvironmentProperties() {
- MetaInfo mi = this.metaInfo;
- if (mi == null) {
- mi = MetaInfoBuilder.of("environment.properties").build();
- } else {
- mi = MetaInfoBuilder.of(metaInfo).build();
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<System.getenv()>";
}
-
return addProviders(PropertySourceFactory.fromEnvironmentProperties());
}
@@ -339,17 +295,24 @@ public final class PropertySourceBuilder {
* @return the builder for chaining.
*/
public PropertySourceBuilder addSystemProperties() {
- MetaInfo mi = this.metaInfo;
- if (mi == null) {
- mi = MetaInfoBuilder.of("system.properties").build();
- } else {
- mi = MetaInfoBuilder.of(metaInfo).build();
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<System.getProperties()>";
}
-
return addProviders(PropertySourceFactory.fromSystemProperties());
}
/**
+ * Add the name used for the next aggregation/adding operation on this builder.
+ * @param name the name to be used, not null.
+ * @return the builder for chaining.
+ */
+ public PropertySourceBuilder withName(String name) {
+ this. currentName = Objects.requireNonNull(name);
+ return this;
+ }
+
+ /**
* Adds the given {@link org.apache.tamaya.PropertySource} instances using the current {@link org.apache.tamaya.AggregationPolicy}
* active.
*
@@ -360,14 +323,11 @@ public final class PropertySourceBuilder {
if(providers.length==0){
return this;
}
- MetaInfo mi = this.metaInfo;
- if (mi == null) {
- mi = MetaInfoBuilder.of("aggregate").build();
- } else {
- mi = MetaInfoBuilder.of(metaInfo).build();
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<aggregate> -> " + Arrays.toString(providers);
}
-
- return addProviders(PropertySourceFactory.aggregate(mi, aggregationPolicy, Arrays.asList(providers)));
+ return addProviders(PropertySourceFactory.aggregate(name, aggregationPolicy, Arrays.asList(providers)));
}
@@ -382,14 +342,11 @@ public final class PropertySourceBuilder {
if(providers.isEmpty()){
return this;
}
- MetaInfo mi = this.metaInfo;
- if (mi == null) {
- mi = MetaInfoBuilder.of("aggregate").build();
- } else {
- mi = MetaInfoBuilder.of(metaInfo).build();
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<aggregate> -> " + providers;
}
-
- return addProviders(PropertySourceFactory.aggregate(mi, aggregationPolicy, providers));
+ return addProviders(PropertySourceFactory.aggregate(name, aggregationPolicy, providers));
}
@@ -415,14 +372,11 @@ public final class PropertySourceBuilder {
if(providers.length==0){
return this;
}
- MetaInfo mi = this.metaInfo;
- if (mi == null) {
- mi = MetaInfoBuilder.of("intersect").build();
- } else {
- mi = MetaInfoBuilder.of(metaInfo).build();
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<intersection> -> " + Arrays.toString(providers);
}
-
- return addProviders(PropertySourceFactory.intersected(mi, aggregationPolicy, Arrays.asList(providers)));
+ return addProviders(PropertySourceFactory.intersected(name, aggregationPolicy, Arrays.asList(providers)));
}
@@ -436,13 +390,11 @@ public final class PropertySourceBuilder {
if(providers.length==0){
return this;
}
- MetaInfo mi = this.metaInfo;
- if (mi == null) {
- mi = MetaInfoBuilder.of("subtract").build();
- } else {
- mi = MetaInfoBuilder.of(metaInfo).build();
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<subtraction> -> " + Arrays.toString(providers);
}
- current = PropertySourceFactory.subtracted(mi, current, Arrays.asList(providers));
+ current = PropertySourceFactory.subtracted(name, current, Arrays.asList(providers));
return this;
}
@@ -454,15 +406,12 @@ public final class PropertySourceBuilder {
* @return the new filtering instance.
*/
public PropertySourceBuilder filter(Predicate<String> filter) {
- MetaInfo mi = this.metaInfo;
- if (mi == null) {
- mi = MetaInfoBuilder.of("filtered").set("filter", filter.toString()).build();
- } else {
- mi = MetaInfoBuilder.of(metaInfo).set("filter", filter.toString()).build();
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<filtered> -> " + filter;
}
- current = PropertySourceFactory.filtered(mi, filter, current);
- addProviderChainInfo("filter->" + filter.toString());
- this.metaInfo = null;
+ current = PropertySourceFactory.filtered(name, filter, current);
+ this.currentName = null;
return this;
}
@@ -475,14 +424,11 @@ public final class PropertySourceBuilder {
*/
public PropertySourceBuilder addContextual(Supplier<PropertySource> mapSupplier,
Supplier<String> isolationKeySupplier) {
- MetaInfo mi = this.metaInfo;
- if (mi == null) {
- mi = MetaInfoBuilder.of("contextual").set("mapSupplier", mapSupplier.toString()).set("isolationKeySupplier", isolationKeySupplier.toString()).build();
- } else {
- mi = MetaInfoBuilder.of(metaInfo).set("mapSupplier", mapSupplier.toString()).set("isolationKeySupplier", isolationKeySupplier.toString()).build();
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<contextual> -> map="+mapSupplier+",isolationKeySupplier="+isolationKeySupplier;
}
-
- return addProviders(PropertySourceFactory.contextual(mi, mapSupplier, isolationKeySupplier));
+ return addProviders(PropertySourceFactory.contextual(name, mapSupplier, isolationKeySupplier));
}
/**
@@ -492,28 +438,12 @@ public final class PropertySourceBuilder {
* @return the new delegating instance.
*/
public PropertySourceBuilder replace(Map<String, String> replacementMap) {
- MetaInfo mi = this.metaInfo;
- if (mi == null) {
- mi = MetaInfoBuilder.of("replace").build();
- } else {
- mi = MetaInfoBuilder.of(metaInfo).build();
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<replacement> -> current="+current.getName()+" with ="+replacementMap;
}
- current = PropertySourceFactory.replacing(mi, current, replacementMap);
- this.metaInfo = null;
- addProviderChainInfo("replace->" + replacementMap.toString());
- return this;
- }
-
- /**
- * Sets an additional key on the final {@link org.apache.tamaya.MetaInfo} of the provider
- * created.
- *
- * @param key the key to be added, not null.
- * @param value the keys to be added, not null.
- * @return this builder for chaining
- */
- public PropertySourceBuilder setMeta(String key, String value){
- this.metaInfoBuilder.set(key, value);
+ current = PropertySourceFactory.replacing(name, current, replacementMap);
+ this.currentName = null;
return this;
}
@@ -523,10 +453,9 @@ public final class PropertySourceBuilder {
*/
public PropertySource build(){
if (current != null) {
- return PropertySourceFactory.build(metaInfoBuilder.build(), current);
+ return PropertySourceFactory.build(name, current);
}
-
- return PropertySourceFactory.empty(metaInfoBuilder.build());
+ return PropertySourceFactory.empty(name);
}
/**
@@ -536,15 +465,12 @@ public final class PropertySourceBuilder {
* @return the freezed instance, never null.
*/
public PropertySource buildFreezed() {
- MetaInfo mi = this.metaInfo;
- if (mi == null) {
- mi = MetaInfoBuilder.of("freezed").set("freezed", "true").build();
- } else {
- mi = MetaInfoBuilder.of(metaInfo).set("freezed", "true").build();
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<freezed> -> source="+current.getName();
}
-
- PropertySource prov = PropertySourceFactory.freezed(mi, current);
- this.metaInfo = null;
+ PropertySource prov = PropertySourceFactory.freezed(name, current);
+ this.currentName = null;
return prov;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFactory.java b/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFactory.java
index b007ea8..34b1cd9 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFactory.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFactory.java
@@ -20,12 +20,7 @@ package org.apache.tamaya.core.properties;
import java.net.URL;
import java.time.Instant;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.function.Predicate;
import java.util.function.Supplier;
@@ -39,7 +34,7 @@ import org.apache.tamaya.PropertySource;
*/
public final class PropertySourceFactory {
- private static final PropertySource EMPTY_PROPERTYSOURCE = fromMap(MetaInfo.of("<empty>"), Collections.emptyMap());
+ private static final PropertySource EMPTY_PROPERTYSOURCE = fromMap("<empty>", Collections.emptyMap());
private static final PropertySource ENV_PROPERTYSOURCE = new EnvironmentPropertySource();
@@ -48,9 +43,9 @@ public final class PropertySourceFactory {
*/
private PropertySourceFactory(){}
- public static PropertySource fromArgs(MetaInfo metaInfo, String... args) {
- if(metaInfo==null){
- metaInfo = MetaInfo.of("CLI");
+ public static PropertySource fromArgs(String name, String... args) {
+ if(name==null){
+ name ="<CLI> " + Arrays.toString(args);
}
// TODO read the CLI with some better library, e.g. move parsing service to ext. service SPI
Map<String, String> properties = new HashMap<>();
@@ -91,35 +86,35 @@ public final class PropertySourceFactory {
properties.put(argKey, value);
}
}
- return fromMap(metaInfo, properties);
+ return fromMap(name, properties);
}
- public static PropertySource fromPaths(MetaInfo metaInfo, AggregationPolicy aggregationPolicy, List<String> paths) {
- if(metaInfo == null){
- metaInfo = MetaInfoBuilder.of().setInfo("From Paths").set("paths", paths.toString()).build();
+ public static PropertySource fromPaths(String name, AggregationPolicy aggregationPolicy, List<String> paths) {
+ if(name==null){
+ name ="<Paths> " + paths.toString();
}
- return new PathBasedPropertySource(metaInfo, paths, aggregationPolicy);
+ return new PathBasedPropertySource(name, paths, aggregationPolicy);
}
- public static PropertySource fromURLs(MetaInfo metaInfo, AggregationPolicy aggregationPolicy, List<URL> resources) {
- if(metaInfo == null){
- metaInfo = MetaInfoBuilder.of().setInfo("From Resources").set("resources", resources.toString()).build();
+ public static PropertySource fromURLs(String name, AggregationPolicy aggregationPolicy, List<URL> urls) {
+ if(name==null){
+ name ="<URLs> " + urls.toString();
}
- return new URLBasedPropertySource(metaInfo, resources, aggregationPolicy);
+ return new URLBasedPropertySource(name, urls, aggregationPolicy);
}
- public static PropertySource fromMap(MetaInfo metaInfo, Map<String, String> map) {
- if(metaInfo == null){
- metaInfo = MetaInfoBuilder.of().setInfo("From Map").set("map", map.toString()).build();
+ public static PropertySource fromMap(String name, Map<String, String> map) {
+ if(name==null){
+ name ="<Map> " + map.toString();
}
- return new MapBasedPropertySource(metaInfo, map);
+ return new MapBasedPropertySource(name, map);
}
- public static PropertySource empty(MetaInfo metaInfo) {
- if(metaInfo==null) {
+ public static PropertySource empty(String name) {
+ if(name==null) {
return EMPTY_PROPERTYSOURCE;
}
- return fromMap(metaInfo, Collections.emptyMap());
+ return fromMap(name, Collections.emptyMap());
}
/**
@@ -140,20 +135,11 @@ public final class PropertySourceFactory {
return new SystemPropertiesPropertySource();
}
- public static PropertySource freezed(MetaInfo metaInfo, PropertySource provider) {
- if(metaInfo==null){
- metaInfo = MetaInfoBuilder.of().setType("freezed")
- .set("provider", provider.toString())
- .set("freezedAt", Date.from(Instant.now()).toString())
- .build();
+ public static PropertySource freezed(String name, PropertySource source) {
+ if(name==null){
+ name ="<Freezed> source=" + source.toString()+", at="+Instant.now().toString();
}
- else{
- metaInfo = MetaInfoBuilder.of(metaInfo).setType("freezed")
- .set("freezedAt", Date.from(Instant.now()).toString())
- .set("provider", provider.toString())
- .build();
- }
- return FreezedPropertySource.of(metaInfo, provider);
+ return FreezedPropertySource.of(name, source);
}
/**
@@ -163,14 +149,11 @@ public final class PropertySourceFactory {
* @param providers the maps to be included, not null.
* @return the aggregated instance containing all given maps.
*/
- public static PropertySource aggregate(MetaInfo metaInfo, AggregationPolicy policy, List<PropertySource> providers) {
- if(metaInfo==null){
- metaInfo = MetaInfoBuilder.of().setInfo("Aggregated")
- .set("AggregationPolicy", policy.toString())
- .set("config", providers.toString())
- .build();
+ public static PropertySource aggregate(String name, AggregationPolicy policy, List<PropertySource> providers) {
+ if(name==null){
+ name ="<Aggregate> policy=" + policy.toString()+", providers="+providers.toString();
}
- return new AggregatedPropertySource(metaInfo, null, policy, providers);
+ return new AggregatedPropertySource(name, null, policy, providers);
}
/**
@@ -179,17 +162,15 @@ public final class PropertySourceFactory {
* @param provider the provider to be made mutable, not null.
* @return the mutable instance.
*/
- public static PropertySource mutable(MetaInfo metaInfo, PropertySource provider) {
- if(metaInfo==null){
- metaInfo = MetaInfoBuilder.of(provider.getMetaInfo())
- .set("mutableSince", Date.from(Instant.now()).toString())
- .build();
+ public static PropertySource mutable(String name, PropertySource provider) {
+ if(name==null){
+ name ="<Mutable> provider="+provider.getName();
}
- PropertySource mutableProvider = fromMap(metaInfo,new HashMap<>());
+ PropertySource mutableProvider = fromMap(name,new HashMap<>());
List<PropertySource> providers = new ArrayList<>(2);
providers.add(provider);
providers.add(mutableProvider);
- return new AggregatedPropertySource(metaInfo, mutableProvider, AggregationPolicy.OVERRIDE, providers);
+ return new AggregatedPropertySource(name, mutableProvider, AggregationPolicy.OVERRIDE, providers);
}
/**
@@ -199,8 +180,8 @@ public final class PropertySourceFactory {
* @param providers the maps to be included, not null.
* @return the intersecting instance containing all given maps.
*/
- public static PropertySource intersected(MetaInfo metaInfo, AggregationPolicy aggregationPolicy, List<PropertySource> providers) {
- return new IntersectingPropertySource(metaInfo, aggregationPolicy, providers);
+ public static PropertySource intersected(String name, AggregationPolicy aggregationPolicy, List<PropertySource> providers) {
+ return new IntersectingPropertySource(name, aggregationPolicy, providers);
}
/**
@@ -211,8 +192,8 @@ public final class PropertySourceFactory {
* @param subtrahendSets the maps to be subtracted, not null.
* @return the intersecting instance containing all given maps.
*/
- public static PropertySource subtracted(MetaInfo metaInfo, PropertySource target, List<PropertySource> subtrahendSets) {
- return new SubtractingPropertySource(metaInfo, target,subtrahendSets);
+ public static PropertySource subtracted(String name, PropertySource target, List<PropertySource> subtrahendSets) {
+ return new SubtractingPropertySource(name, target,subtrahendSets);
}
@@ -220,12 +201,15 @@ public final class PropertySourceFactory {
* Creates a filtered {@link org.apache.tamaya.PropertySource} (a view) current a given base {@link }PropertyMap}. The filter hereby is
* applied dynamically on access, so also runtime changes current the base map are reflected appropriately.
*
- * @param propertyMap the base map instance, not null.
+ * @param name the base map instance, not null.
* @param filter the filtger to be applied, not null.
* @return the new filtering instance.
*/
- public static PropertySource filtered(MetaInfo metaInfo, Predicate<String> filter, PropertySource propertyMap) {
- return new FilteredPropertySource(metaInfo, propertyMap, filter);
+ public static PropertySource filtered(String name, Predicate<String> filter, PropertySource source) {
+ if(name==null){
+ name ="<Filtered> filter="+filter+", source="+source.getName();
+ }
+ return new FilteredPropertySource(name, source, filter);
}
/**
@@ -235,9 +219,12 @@ public final class PropertySourceFactory {
* @param mapSupplier the supplier creating new provider instances
* @param isolationKeySupplier the supplier providing contextual keys based on the current environment.
*/
- public static PropertySource contextual(MetaInfo metaInfo, Supplier<PropertySource> mapSupplier,
+ public static PropertySource contextual(String name, Supplier<PropertySource> mapSupplier,
Supplier<String> isolationKeySupplier) {
- return new ContextualPropertySource(metaInfo, mapSupplier, isolationKeySupplier);
+ if(name==null){
+ name ="<Contextual> mapSupplier="+mapSupplier+", isolationKeyProvider="+isolationKeySupplier;
+ }
+ return new ContextualPropertySource(name, mapSupplier, isolationKeySupplier);
}
@@ -245,12 +232,15 @@ public final class PropertySourceFactory {
* Creates a filtered {@link org.apache.tamaya.PropertySource} (a view) current a given base {@link }PropertyMap}. The filter hereby is
* applied dynamically on access, so also runtime changes current the base map are reflected appropriately.
*
- * @param mainMap the main map instance, not null.
+ * @param source the main map instance, not null.
* @param parentMap the delegated parent map instance, not null.
* @return the new delegating instance.
*/
- public static PropertySource delegating(MetaInfo metaInfo, PropertySource mainMap, Map<String, String> parentMap) {
- return new DelegatingPropertySource(metaInfo, mainMap, parentMap);
+ public static PropertySource delegating(String name, PropertySource source, Map<String, String> parentMap) {
+ if(name==null){
+ name ="<Delegating> source="+source+", delegates="+parentMap;
+ }
+ return new DelegatingPropertySource(name, source, parentMap);
}
/**
@@ -266,19 +256,22 @@ public final class PropertySourceFactory {
* @param replacementMap the map instance, that will replace all corresponding entries in {@code mainMap}, not null.
* @return the new delegating instance.
*/
- public static PropertySource replacing(MetaInfo metaInfo, PropertySource mainMap, Map<String, String> replacementMap) {
- return new ReplacingPropertySource(metaInfo, mainMap, replacementMap);
+ public static PropertySource replacing(String name, PropertySource source, Map<String, String> replacementMap) {
+ if(name==null){
+ name ="<Replacement> source="+source+", replacements="+replacementMap;
+ }
+ return new ReplacingPropertySource(name, source, replacementMap);
}
/**
* Creates a new {@link org.apache.tamaya.PropertySource} given an existing one, and an alternate
* meta-info.
- * @param metaInfo the new meta-information, not null.
+ * @param name the new meta-information, not null.
* @param baseProvider the property source, not null.
* @return the new property source.never null.
*/
- public static PropertySource build(MetaInfo metaInfo, PropertySource baseProvider) {
- return new BuildablePropertySource(metaInfo, baseProvider);
+ public static PropertySource build(String name, PropertySource baseProvider) {
+ return new BuildablePropertySource(name, baseProvider);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
index dfc68c2..a5f49fe 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
@@ -34,7 +34,7 @@ class ReplacingPropertySource implements PropertySource {
private PropertySource mainMap;
private Map<String,String> replacingMap;
- private MetaInfo metaInfo;
+ private String name;
/**
* Creates a mew instance, with aggregation polilcy
@@ -43,17 +43,10 @@ class ReplacingPropertySource implements PropertySource {
* @param mainMap The main ConfigMap.
* @param replacingMap The replacing ConfigMap.
*/
- public ReplacingPropertySource(MetaInfo metaInfo, PropertySource mainMap, Map<String, String> replacingMap){
+ public ReplacingPropertySource(String name, PropertySource mainMap, Map<String, String> replacingMap){
this.replacingMap = Objects.requireNonNull(replacingMap);
this.mainMap = Objects.requireNonNull(mainMap);
- if(metaInfo==null) {
- this.metaInfo = MetaInfoBuilder.of().setType("replacing").set("mainProvider", mainMap.toString())
- .set("replacing", replacingMap.toString()).build();
- }
- else{
- this.metaInfo = MetaInfoBuilder.of(metaInfo).setType("replacing").set("mainProvider", mainMap.toString())
- .set("replacing", replacingMap.toString()).build();
- }
+ this.name = Objects.requireNonNull(name);
}
@Override
@@ -62,21 +55,16 @@ class ReplacingPropertySource implements PropertySource {
}
@Override
- public boolean containsKey(String key){
- return mainMap.containsKey(key);
- }
-
- @Override
- public Map<String,String> toMap(){
+ public Map<String,String> getProperties(){
Map<String,String> result = new HashMap<>(replacingMap);
- mainMap.toMap().entrySet().stream().filter(en -> !replacingMap.containsKey(en.getKey())).forEach(en ->
+ mainMap.getProperties().entrySet().stream().filter(en -> !replacingMap.containsKey(en.getKey())).forEach(en ->
result.put(en.getKey(), en.getValue()));
return result;
}
@Override
- public MetaInfo getMetaInfo(){
- return this.metaInfo;
+ public String getName(){
+ return this.name;
}
@Override
@@ -88,11 +76,6 @@ class ReplacingPropertySource implements PropertySource {
return Optional.ofNullable(val);
}
- @Override
- public Set<String> keySet(){
- return mainMap.keySet();
- }
-
/**
* Apply a config change to this item. Hereby the change must be related to the same instance.
* @param change the config change
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/SubtractingPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/SubtractingPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/SubtractingPropertySource.java
index dc02693..748c86e 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/SubtractingPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/SubtractingPropertySource.java
@@ -32,9 +32,8 @@ class SubtractingPropertySource extends AbstractPropertySource {
private PropertySource unit;
private List<PropertySource> subtrahends;
- public SubtractingPropertySource(MetaInfo metaInfo, PropertySource configuration, List<PropertySource> subtrahends){
- super(metaInfo==null?MetaInfoBuilder.of(configuration.getMetaInfo()).setType("subtracted").build():
- MetaInfoBuilder.of(metaInfo).setType("subtracted").build());
+ public SubtractingPropertySource(String name, PropertySource configuration, List<PropertySource> subtrahends){
+ super(name);
Objects.requireNonNull(configuration);
this.unit = configuration;
this.subtrahends = new ArrayList<>(subtrahends);
@@ -42,7 +41,7 @@ class SubtractingPropertySource extends AbstractPropertySource {
private boolean filter(Map.Entry<String,String> entry){
for(PropertySource prov: subtrahends){
- if(prov.containsKey(entry.getKey())){
+ if(prov.get(entry.getKey()).isPresent()){
return false;
}
}
@@ -50,8 +49,8 @@ class SubtractingPropertySource extends AbstractPropertySource {
}
@Override
- public Map<String,String> toMap(){
- return this.unit.toMap().entrySet().stream().filter(this::filter).collect(Collectors.toMap(
+ public Map<String,String> getProperties(){
+ return this.unit.getProperties().entrySet().stream().filter(this::filter).collect(Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue
));
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/SystemPropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/SystemPropertiesPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/SystemPropertiesPropertySource.java
index b9b3a31..f66c4f8 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/SystemPropertiesPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/SystemPropertiesPropertySource.java
@@ -18,10 +18,6 @@
*/
package org.apache.tamaya.core.properties;
-import org.apache.tamaya.MetaInfoBuilder;
-import org.apache.tamaya.core.env.ConfiguredSystemProperties;
-import org.apache.tamaya.core.properties.AbstractPropertySource;
-
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -32,16 +28,19 @@ class SystemPropertiesPropertySource extends AbstractPropertySource {
private static final long serialVersionUID = -5935940312707001199L;
- public SystemPropertiesPropertySource(){
- super(MetaInfoBuilder.of().setType("sys-properties").build());
+ /**
+ * Constructor.
+ */
+ protected SystemPropertiesPropertySource() {
+ super("<System.getProperties()>");
}
@Override
- public Map<String,String> toMap(){
+ public Map<String,String> getProperties(){
Properties sysProps = System.getProperties();
- if(sysProps instanceof ConfiguredSystemProperties){
- sysProps = ((ConfiguredSystemProperties)sysProps).getInitialProperties();
- }
+// if(sysProps instanceof ConfiguredSystemProperties){
+// sysProps = ((ConfiguredSystemProperties)sysProps).getInitialProperties();
+// }
Map<String,String> props = new HashMap<>();
for (Map.Entry<Object,Object> en : sysProps.entrySet()) {
props.put(en.getKey().toString(), en.getValue().toString());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java
index a3ae395..8086c23 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java
@@ -20,13 +20,9 @@ package org.apache.tamaya.core.properties;
import org.apache.tamaya.AggregationPolicy;
import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.MetaInfo;
-import org.apache.tamaya.MetaInfoBuilder;
-import org.apache.tamaya.core.config.ConfigurationFormats;
import org.apache.tamaya.core.internal.resources.io.UrlResource;
-import org.apache.tamaya.core.properties.AbstractPropertySource;
import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.spi.ConfigurationFormat;
+import org.apache.tamaya.core.config.ConfigurationFormat;
import java.net.URL;
import java.util.*;
@@ -41,8 +37,8 @@ final class URLBasedPropertySource extends AbstractPropertySource {
private Map<String,String> properties = new HashMap<>();
private AggregationPolicy aggregationPolicy;
- public URLBasedPropertySource(MetaInfo metaInfo, List<URL> resources, AggregationPolicy aggregationPolicy) {
- super(metaInfo);
+ public URLBasedPropertySource(String name, List<URL> resources, AggregationPolicy aggregationPolicy) {
+ super(name);
this.resources.addAll(Objects.requireNonNull(resources));
this.aggregationPolicy = Objects.requireNonNull(aggregationPolicy);
init();
@@ -52,7 +48,7 @@ final class URLBasedPropertySource extends AbstractPropertySource {
List<String> sources = new ArrayList<>();
for(URL url : resources){
Resource res = new UrlResource(url);
- ConfigurationFormat format = ConfigurationFormats.getFormat(res);
+ ConfigurationFormat format = ConfigurationFormat.from(res);
if(format != null){
try{
Map<String, String> read = format.readConfiguration(res);
@@ -75,13 +71,13 @@ final class URLBasedPropertySource extends AbstractPropertySource {
}
}
}
- MetaInfoBuilder metaInfoBuilder = MetaInfoBuilder.of(getMetaInfo());
- metaInfo = metaInfoBuilder
- .setSources(sources.toString()).build();
+// MetaInfoBuilder metaInfoBuilder = MetaInfoBuilder.of(getMetaInfo());
+// metaInfo = metaInfoBuilder
+// .setSources(sources.toString()).build();
}
@Override
- public Map<String, String> toMap() {
+ public Map<String, String> getProperties() {
return properties;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java b/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java
index f4f86e9..52e6f47 100644
--- a/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java
+++ b/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java
@@ -46,7 +46,7 @@ public interface ResourceLoader{
*
* @param expressions the expressions to be resolved, not empty.
* @return the corresponding collection current {@link java.net.URI}s defining the
- * concrete resources to be read by a {@link org.apache.tamaya.core.spi.ConfigurationFormat}
+ * concrete resources to be read by a {@link org.apache.tamaya.core.config.ConfigurationFormat}
* .
*/
List<Resource> getResources(String... expressions);
@@ -56,7 +56,7 @@ public interface ResourceLoader{
*
* @param expressions the expressions to be resolved, not empty.
* @return the corresponding collection current {@link java.net.URI}s defining the
- * concrete resources to be read by a {@link org.apache.tamaya.core.spi.ConfigurationFormat}
+ * concrete resources to be read by a {@link org.apache.tamaya.core.config.ConfigurationFormat}
* .
*/
List<Resource> getResources(Collection<String> expressions);
@@ -66,7 +66,7 @@ public interface ResourceLoader{
*
* @param expressions the expressions to be resolved, not empty.
* @return the corresponding collection current {@link java.net.URI}s defining the
- * concrete resources to be read by a {@link org.apache.tamaya.core.spi.ConfigurationFormat}
+ * concrete resources to be read by a {@link org.apache.tamaya.core.config.ConfigurationFormat}
* .
*/
List<Resource> getResources(ClassLoader classLoader, String... expressions);
@@ -76,7 +76,7 @@ public interface ResourceLoader{
*
* @param expressions the expressions to be resolved, not empty.
* @return the corresponding collection current {@link java.net.URI}s defining the
- * concrete resources to be read by a {@link org.apache.tamaya.core.spi.ConfigurationFormat}
+ * concrete resources to be read by a {@link org.apache.tamaya.core.config.ConfigurationFormat}
* .
*/
List<Resource> getResources(ClassLoader classLoader, Collection<String> expressions);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/spi/AdapterProviderSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/spi/AdapterProviderSpi.java b/core/src/main/java/org/apache/tamaya/core/spi/AdapterProviderSpi.java
deleted file mode 100644
index 6cb6dc1..0000000
--- a/core/src/main/java/org/apache/tamaya/core/spi/AdapterProviderSpi.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.core.spi;
-
-import org.apache.tamaya.Codec;
-
-/**
- * This service provides different {@link org.apache.tamaya.Codec} instances for types.
- */
-public interface AdapterProviderSpi{
-
- /**
- * Called, when a given {@link org.apache.tamaya.Configuration} has to be evaluated.
- *
- * @return the corresponding {@link java.util.function.Function<String, T>}, or {@code null}, if
- * not available for the given target type.
- */
- <T> Codec<T> getAdapter(Class<T> type);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/spi/CodecProviderSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/spi/CodecProviderSpi.java b/core/src/main/java/org/apache/tamaya/core/spi/CodecProviderSpi.java
new file mode 100644
index 0000000..b814037
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/spi/CodecProviderSpi.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.core.spi;
+
+import org.apache.tamaya.Codec;
+
+/**
+ * This service provides different {@link org.apache.tamaya.Codec} instances for types.
+ */
+public interface CodecProviderSpi {
+
+ /**
+ * Called, when a given {@link org.apache.tamaya.Configuration} has to be evaluated.
+ *
+ * @return the corresponding {@link java.util.function.Function<String, T>}, or {@code null}, if
+ * not available for the given target type.
+ */
+ <T> Codec<T> getCodec(Class<T> type);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormat.java b/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormat.java
deleted file mode 100644
index cc60905..0000000
--- a/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormat.java
+++ /dev/null
@@ -1,57 +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.core.spi;
-
-import org.apache.tamaya.core.resource.Resource;
-
-import java.util.Map;
-
-/**
- * Implementations current this class encapsulate the mechanism how to read a
- * resource URI including interpreting the format correctly (e.g. xml vs.
- * properties).
- */
-public interface ConfigurationFormat{
-
- /**
- * Returns a unique identifier that identifies each format.
- *
- * @return the unique format id, mever null.
- */
- public String getFormatName();
-
- /**
- * Check if the given {@link java.net.URI} and path xpression qualify that this format should be
- * able to read them, e.g. checking for compatible file endings.
- *
- * @param resource the configuration location, not null
- * @return {@code true} if the given resource is in a format supported by
- * this instance.
- */
- boolean isAccepted(Resource resource);
-
- /**
- * Reads a {@link org.apache.tamaya.PropertySource} fromMap the given URI, using this format.
- *
- * @param resource the configuration location, not null
- * @return the corresponding {@link java.util.Map}, never {@code null}.
- */
- Map<String,String> readConfiguration(Resource resource);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java b/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java
new file mode 100644
index 0000000..7df988b
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.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.core.spi;
+
+import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.resource.Resource;
+
+import java.util.Collection;
+
+/**
+ * Created by Anatole on 17.09.2014.
+ */
+public interface ConfigurationFormatSpi {
+ /**
+ * Access a {@link org.apache.tamaya.core.config.ConfigurationFormat}.
+ *
+ * @param formatName the format name
+ * @return the corresponding {@link org.apache.tamaya.core.config.ConfigurationFormat}, or {@code null}, if
+ * not available for the given environment.
+ */
+ ConfigurationFormat getFormat(String formatName);
+
+ /**
+ * Get a collection current the keys current the registered {@link org.apache.tamaya.core.config.ConfigurationFormat} instances.
+ *
+ * @return a collection current the keys current the registered {@link ConfigurationFormat} instances.
+ */
+ Collection<String> getFormatNames();
+
+ /**
+ * Evaluate the matching format for a given resource.
+ *
+ * @param resource The resource
+ * @return a matching configuration format, or {@code null} if no matching format could be determined.
+ */
+ ConfigurationFormat getFormat(Resource resource);
+
+ default ConfigurationFormat getPropertiesFormat(){
+ return getFormat("properties");
+ }
+
+ default ConfigurationFormat getXmlPropertiesFormat(){
+ return getFormat("xml-properties");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatsSingletonSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatsSingletonSpi.java b/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatsSingletonSpi.java
deleted file mode 100644
index 260f945..0000000
--- a/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatsSingletonSpi.java
+++ /dev/null
@@ -1,60 +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.core.spi;
-
-import org.apache.tamaya.core.resource.Resource;
-
-import java.util.Collection;
-
-/**
- * Created by Anatole on 17.09.2014.
- */
-public interface ConfigurationFormatsSingletonSpi{
- /**
- * Access a {@link org.apache.tamaya.core.spi.ConfigurationFormat}.
- *
- * @param formatName the format name
- * @return the corresponding {@link org.apache.tamaya.core.spi.ConfigurationFormat}, or {@code null}, if
- * not available for the given environment.
- */
- ConfigurationFormat getFormat(String formatName);
-
- /**
- * Get a collection current the keys current the registered {@link ConfigurationFormat} instances.
- *
- * @return a collection current the keys current the registered {@link ConfigurationFormat} instances.
- */
- Collection<String> getFormatNames();
-
- /**
- * Evaluate the matching format for a given resource.
- *
- * @param resource The resource
- * @return a matching configuration format, or {@code null} if no matching format could be determined.
- */
- ConfigurationFormat getFormat(Resource resource);
-
- default ConfigurationFormat getPropertiesFormat(){
- return getFormat("properties");
- }
-
- default ConfigurationFormat getXmlPropertiesFormat(){
- return getFormat("xml-properties");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/spi/EnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/spi/EnvironmentProvider.java b/core/src/main/java/org/apache/tamaya/core/spi/EnvironmentProvider.java
deleted file mode 100644
index 3696db9..0000000
--- a/core/src/main/java/org/apache/tamaya/core/spi/EnvironmentProvider.java
+++ /dev/null
@@ -1,46 +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.core.spi;
-
-import java.util.Map;
-
-import org.apache.tamaya.Environment;
-
-/**
- * SPI for components that define a concrete type current {@link org.apache.tamaya.Environment}.
- * The chain current environment config determine the current {@link Environment} active
- * and its parent instances.
- * Created by Anatole on 14.10.2014.
- */
-public interface EnvironmentProvider {
-
- /**
- * Evaluates if an environment is currently active.
- * @return
- */
- boolean isActive();
-
- /**
- * Returns the properties to be added to the environment.
- * @return the properties, or an empty map if no properties are to be added (or the provider is not active for the
- * current runtime state).
- */
- Map<String,String> getEnvironmentData();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/spi/ObjectConfiguratorService.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/spi/ObjectConfiguratorService.java b/core/src/main/java/org/apache/tamaya/core/spi/ObjectConfiguratorService.java
deleted file mode 100644
index e26aa07..0000000
--- a/core/src/main/java/org/apache/tamaya/core/spi/ObjectConfiguratorService.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.core.spi;
-
-
-import org.apache.tamaya.Configuration;
-
-/**
- * Service used for resolving configuration annotations.
- */
-public interface ObjectConfiguratorService{
-
- /**
- * Inject fields annotated for configuration.
- *
- * @param instance
- * The instance to be configured.
- */
- void configure(Object instance, Configuration configuration);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/spi/ObjectConfiguratorSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/spi/ObjectConfiguratorSpi.java b/core/src/main/java/org/apache/tamaya/core/spi/ObjectConfiguratorSpi.java
new file mode 100644
index 0000000..9f38792
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/spi/ObjectConfiguratorSpi.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.spi;
+
+
+import org.apache.tamaya.Configuration;
+
+/**
+ * Service used for resolving configuration annotations.
+ */
+public interface ObjectConfiguratorSpi {
+
+ /**
+ * Inject fields annotated for configuration.
+ *
+ * @param instance
+ * The instance to be configured.
+ */
+ void configure(Object instance, Configuration configuration);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterService.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterService.java b/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterService.java
index 199f5a9..9270636 100644
--- a/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterService.java
+++ b/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterService.java
@@ -1,64 +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.core.spi;
-
-import java.io.File;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.tamaya.Codec;
-
-@SuppressWarnings("unchecked")
-public interface PropertyAdapterService{
-
- public default Codec<URL> getURLAdapter(){
- return Codec.class.cast(getClassAdapter(URL.class));
- }
-
- public default Codec<InputStream> getClasspathResourceAdapter(){
- return Codec.class.cast(getClassAdapter(InputStream.class));
- }
-
- public default Codec<File> getFileAdapter(){
- return Codec.class.cast(getClassAdapter(File.class));
- }
-
- public default Codec<Set<String>> getSetAdapter(){
- return Codec.class.cast(getClassAdapter(Set.class));
- }
-
- public default Codec<Map<String, String>> getMapAdapter(){
- return Codec.class.cast(getClassAdapter(Map.class));
- }
-
- public default Codec<List<String>> getListAdapter(){
- return Codec.class.cast(getClassAdapter(List.class));
- }
-
- public default <T> Codec<Class<? extends T>> getClassAdapter(Class<T> requiredType){
- return getClassAdapter(requiredType, Thread.currentThread().getContextClassLoader());
- }
-
- public <T> Codec<Class<? extends T>> getClassAdapter(Class<T> requiredType,
- ClassLoader... classLoaders);
-
-}
+///*
+// * Licensed to the Apache Software Foundation (ASF) under one
+// * or more contributor license agreements. See the NOTICE file
+// * distributed with this work for additional information
+// * regarding copyright ownership. The ASF licenses this file
+// * to you under the Apache License, Version 2.0 (the
+// * "License"); you may not use this file except in compliance
+// * with the License. You may obtain a copy of the License at
+// *
+// * http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing,
+// * software distributed under the License is distributed on an
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// * KIND, either express or implied. See the License for the
+// * specific language governing permissions and limitations
+// * under the License.
+// */
+//package org.apache.tamaya.core.spi;
+//
+//import java.io.File;
+//import java.io.InputStream;
+//import java.net.URL;
+//import java.util.List;
+//import java.util.Map;
+//import java.util.Set;
+//
+//import org.apache.tamaya.Codec;
+//
+//@SuppressWarnings("unchecked")
+//public interface PropertyAdapterService{
+//
+// public default Codec<URL> getURLAdapter(){
+// return Codec.class.cast(getClassAdapter(URL.class));
+// }
+//
+// public default Codec<InputStream> getClasspathResourceAdapter(){
+// return Codec.class.cast(getClassAdapter(InputStream.class));
+// }
+//
+// public default Codec<File> getFileAdapter(){
+// return Codec.class.cast(getClassAdapter(File.class));
+// }
+//
+// public default Codec<Set<String>> getSetAdapter(){
+// return Codec.class.cast(getClassAdapter(Set.class));
+// }
+//
+// public default Codec<Map<String, String>> getMapAdapter(){
+// return Codec.class.cast(getClassAdapter(Map.class));
+// }
+//
+// public default Codec<List<String>> getListAdapter(){
+// return Codec.class.cast(getClassAdapter(List.class));
+// }
+//
+// public default <T> Codec<Class<? extends T>> getClassAdapter(Class<T> requiredType){
+// return getClassAdapter(requiredType, Thread.currentThread().getContextClassLoader());
+// }
+//
+// public <T> Codec<Class<? extends T>> getClassAdapter(Class<T> requiredType,
+// ClassLoader... classLoaders);
+//
+//}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/resources/META-INF/java-config-1.0.0.xsd
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/java-config-1.0.0.xsd b/core/src/main/resources/META-INF/java-config-1.0.0.xsd
deleted file mode 100644
index fa917a0..0000000
--- a/core/src/main/resources/META-INF/java-config-1.0.0.xsd
+++ /dev/null
@@ -1,80 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy current the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://java-config.java.net/metamodel/1.0.0"
- xmlns:tns="http://java-config.java.net/metamodel/1.0.0"
- elementFormDefault="qualified">
-
- <element name="java-config">
- <complexType>
- <sequence>
- <element name="metaModel" minOccurs="1" maxOccurs="1">
- <complexType>
- <sequence>
- <element name="configParts">
- <complexType>
- <sequence>
- <element name="configPart" type="tns:configPart" maxOccurs="unbounded"/>
- </sequence>
- </complexType>
- </element>
- </sequence>
- <attribute name="id" type="string"></attribute>
- </complexType>
- </element>
- </sequence>
- </complexType>
- </element>
-
- <complexType name="configPart">
- <sequence>
- <sequence>
- <element name="properties" type="tns:properties"></element>
- </sequence>
- <sequence>
- <element name="childParts" type="tns:childParts"></element>
- </sequence>
- </sequence>
- <attribute name="key" type="string"></attribute>
- <attribute name="partType" type="string"></attribute>
- <attribute name="propertyMapSpec" type="string"></attribute>
- </complexType>
-
- <complexType name="properties">
- <sequence>
- <element name="comment" type="tns:entry"></element>
- <element name="entry" type="tns:entry"></element>
- </sequence>
- </complexType>
- <complexType name="entry">
- <attribute name="key" type="string"></attribute>
- </complexType>
-
- <complexType name="childParts">
- <sequence>
- <element name="childPart" type="tns:entry">
- <complexType>
- <attribute name="psrtType" type="string"></attribute>
- <attribute name="keyRef" type="string"></attribute>
- </complexType>
- </element>
- </sequence>
- </complexType>
-
-</schema>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/resources/META-INF/java-config.xml
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/java-config.xml b/core/src/main/resources/META-INF/java-config.xml
deleted file mode 100644
index 329f0e6..0000000
--- a/core/src/main/resources/META-INF/java-config.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy current the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<java-config xmlns="http://java.net/projects/javaconfig/java-config/1.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:noNamespaceSchemaLocation="java-config-1.0.0.xsd">
- <metaModel id="default">
- <configParts>
- <configPart key="sys-properties" partType="javax.config.PropertyMap" propertyMapSpec="org.apache.tamaya.core.properties.SystemPropertiesPropertyMap"/>
- <configPart key="env-properties" partType="javax.config.PropertyMap" propertyMapSpec="org.apache.tamaya.core.properties.EnvironmentPropertyMap"/>
- <configPart key="--system--" partType="org.apache.tamaya.Configuration" propertyMapSpec="union">
- <childPart partType="javax.config.PropertyMap" keyRef="sys-properties"/>
- <childPart partType="javax.config.PropertyMap" keyRef="env-properties"/>
- </configPart>
- </configParts>
- </metaModel>
-</java-config>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/resources/META-INF/meta-model.properties
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/meta-model.properties b/core/src/main/resources/META-INF/meta-model.properties
deleted file mode 100644
index dcfc41f..0000000
--- a/core/src/main/resources/META-INF/meta-model.properties
+++ /dev/null
@@ -1,39 +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.
-#
-
-## Register default configuration formats
-format.xml-properties.spec=org.apache.tamaya.org.apache.tamaya.internal.format.PropertiesXmlFormat
-format.properties.spec=org.apache.tamaya.org.apache.tamaya.internal.format.PropertiesFormat
-
-## Define default readers (reading sources)
-reader.classpath.spec=org.apache.tamaya.core.internal.properties.ClasspathPropertyProvider
-reader.file.spec=org.apache.tamaya.core.properties.FilePropertyMap
-
-## Define property maps
-propertymap.environment.spec=union
-propertymap.environment.policy=override
-propertymap.environment.content=env-props[/env],sys-props[/sys],cli[/cli],network[/net]
-propertymap.env-props.spec=org.apache.tamaya.core.properties.EnvironmentPropertyMap
-propertymap.sys-props.spec=org.apache.tamaya.core.properties.SystemPropertiesPropertyMap
-propertymap.network.spec=org.apache.tamaya.core.properties.NetworkPropertyMap
-propertymap.cli.spec=org.apache.tamaya.core.properties.CLIPropertyMap
-
-## Define root configurations
-configuration.default.content=environment[/]
-
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/resources/META-INF/services/org.apache.tamaya.core.config.ConfigurationFormat
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.config.ConfigurationFormat b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.config.ConfigurationFormat
new file mode 100644
index 0000000..7aa2407
--- /dev/null
+++ b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.config.ConfigurationFormat
@@ -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 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.core.internal.format.PropertiesFormat
+org.apache.tamaya.core.internal.format.PropertiesXmlFormat
+org.apache.tamaya.core.internal.format.IniFormat
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resource.ResourceLoader
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resource.ResourceLoader b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resource.ResourceLoader
index f9c0de4..c245d54 100644
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resource.ResourceLoader
+++ b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resource.ResourceLoader
@@ -16,5 +16,5 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.core.internal.resources.DefaultPathResourceLoader
+org.apache.tamaya.core.internal.resources.DefaultResourceLoader
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationFormat
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationFormat b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationFormat
deleted file mode 100644
index 7aa2407..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationFormat
+++ /dev/null
@@ -1,21 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy 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.core.internal.format.PropertiesFormat
-org.apache.tamaya.core.internal.format.PropertiesXmlFormat
-org.apache.tamaya.core.internal.format.IniFormat
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationFormatSpi
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationFormatSpi b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationFormatSpi
new file mode 100644
index 0000000..e81bd2b
--- /dev/null
+++ b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationFormatSpi
@@ -0,0 +1,19 @@
+#
+# 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.core.internal.format.DefaultConfigurationFormatSpi
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationFormatsSingletonSpi
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationFormatsSingletonSpi b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationFormatsSingletonSpi
deleted file mode 100644
index f4f2aa1..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationFormatsSingletonSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.core.internal.format.DefaultConfigFormatsSingletonSpi
\ No newline at end of file
[5/6] incubator-tamaya git commit: TAMAYA-19: - Moved out much of
unused/experimental code. - Reduced API (removing package private singletons)
- Aligned PropertySource with Deltaspike (mostly). - Moved Environment model
to separate metamodel module.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/java/org/apache/tamaya/TestEnvironmentManagerSingleton.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/TestEnvironmentManagerSingleton.java b/api/src/test/java/org/apache/tamaya/TestEnvironmentManagerSingleton.java
deleted file mode 100644
index 30423a6..0000000
--- a/api/src/test/java/org/apache/tamaya/TestEnvironmentManagerSingleton.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;
-
-import org.apache.tamaya.spi.EnvironmentManagerSingletonSpi;
-
-/**
- * Created by Anatole on 12.09.2014.
- */
-public class TestEnvironmentManagerSingleton implements EnvironmentManagerSingletonSpi{
- @Override
- public Environment getCurrentEnvironment(){
- return null;
- }
-
- @Override
- public Environment getRootEnvironment(){
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java b/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
index 8aa6375..b27164c 100644
--- a/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
+++ b/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
@@ -30,14 +30,14 @@ import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.tamaya.annotation.WithCodec;
-import org.apache.tamaya.spi.CodecsSingletonSpi;
+import org.apache.tamaya.spi.CodecSpi;
/**
- * Test implementation current {@link org.apache.tamaya.spi.CodecsSingletonSpi}, which provides codecs
+ * Test implementation current {@link org.apache.tamaya.spi.CodecSpi}, which provides codecs
* for some basic types.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
-public final class TestPropertyAdaptersSingletonSpi implements CodecsSingletonSpi {
+public final class TestPropertyAdaptersSingletonSpi implements CodecSpi {
private Map<Class, Codec<?>> codecs = new ConcurrentHashMap<>();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecSpi
----------------------------------------------------------------------
diff --git a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecSpi b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecSpi
new file mode 100644
index 0000000..e9b04b4
--- /dev/null
+++ b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecSpi
@@ -0,0 +1,19 @@
+#
+# 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.TestPropertyAdaptersSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi
----------------------------------------------------------------------
diff --git a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi
deleted file mode 100644
index e9b04b4..0000000
--- a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.TestPropertyAdaptersSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationManagerSingletonSpi
----------------------------------------------------------------------
diff --git a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationManagerSingletonSpi b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationManagerSingletonSpi
deleted file mode 100644
index 1b0cdd4..0000000
--- a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationManagerSingletonSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.TestConfigServiceSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
----------------------------------------------------------------------
diff --git a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
new file mode 100644
index 0000000..1b0cdd4
--- /dev/null
+++ b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
@@ -0,0 +1,19 @@
+#
+# 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.TestConfigServiceSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentManagerSingletonSpi
----------------------------------------------------------------------
diff --git a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentManagerSingletonSpi b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentManagerSingletonSpi
deleted file mode 100644
index d39ba55..0000000
--- a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentManagerSingletonSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.TestEnvironmentManagerSingleton
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java b/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
index c89e269..b6f54fc 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
@@ -23,7 +23,7 @@ import java.util.UUID;
import org.apache.tamaya.*;
import org.apache.tamaya.core.properties.AbstractPropertySource;
-import org.apache.tamaya.core.spi.AdapterProviderSpi;
+import org.apache.tamaya.core.spi.CodecProviderSpi;
import org.apache.tamaya.spi.ServiceContext;
/**
@@ -36,17 +36,15 @@ public abstract class AbstractConfiguration extends AbstractPropertySource imple
private final Object LOCK = new Object();
- private String version = UUID.randomUUID().toString();
-
- protected AbstractConfiguration(MetaInfo metaInfo){
- super(metaInfo);
+ protected AbstractConfiguration(String name){
+ super(name);
}
@Override
public <T> Optional<T> get(String key, Class<T> type){
- AdapterProviderSpi as = ServiceContext.getInstance().getSingleton(AdapterProviderSpi.class);
- Codec<T> adapter = as.getAdapter(type);
+ CodecProviderSpi as = ServiceContext.getInstance().getSingleton(CodecProviderSpi.class);
+ Codec<T> adapter = as.getCodec(type);
if(adapter == null){
throw new ConfigException(
"Can not deserialize config property '" + key + "' to " + type.getName() + ": no such " +
@@ -55,11 +53,6 @@ public abstract class AbstractConfiguration extends AbstractPropertySource imple
return getAdapted(key, adapter);
}
- @Override
- public String getVersion(){
- return version;
- }
-
/**
* This method reloads the content current this PropertyMap by reloading the contents delegate.
*/
@@ -82,7 +75,6 @@ public abstract class AbstractConfiguration extends AbstractPropertySource imple
if(changeSet.isEmpty()){
return ConfigChangeSet.emptyChangeSet(this);
}
- this.version = UUID.randomUUID().toString();
Configuration.publishChange(changeSet);
return changeSet;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java b/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
index ddd83e2..c1a2518 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
@@ -18,10 +18,12 @@
*/
package org.apache.tamaya.core.config;
+import org.apache.tamaya.ConfigQuery;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.core.properties.PropertySourceBuilder;
import java.util.*;
+import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
@@ -59,7 +61,7 @@ public final class ConfigFunctions {
return config -> {
Map<String, String> area = new HashMap<>();
area.putAll(
- config.toMap().entrySet().stream()
+ config.getProperties().entrySet().stream()
.filter(e -> isKeyInArea(e.getKey(), areaKey))
.collect(Collectors.toMap(
e -> stripKeys ? e.getKey().substring(areaKey.length() + 1) : e.getKey(),
@@ -82,6 +84,98 @@ public final class ConfigFunctions {
}
/**
+ * Return a query to evaluate the set with all fully qualifies area names. This method should return the areas as accurate as possible,
+ * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
+ * does not support key iteration.
+ *
+ * @return s set with all areas, never {@code null}.
+ */
+ public static ConfigQuery<Set<String>> getAreas() {
+ return config -> {
+ final Set<String> areas = new HashSet<>();
+ config.getProperties().keySet().forEach(s -> {
+ int index = s.lastIndexOf('.');
+ if (index > 0) {
+ areas.add(s.substring(0, index));
+ } else {
+ areas.add("<root>");
+ }
+ });
+ return areas;
+ };
+ }
+
+ /**
+ * Return a query to evaluate the set with all fully qualified area names, containing the transitive closure also including all
+ * subarea names, regardless if properties are accessible or not. This method should return the areas as accurate
+ * as possible, but may not provide a complete set of areas that are finally accessible, especially when the
+ * underlying storage does not support key iteration.
+ *
+ * @return s set with all transitive areas, never {@code null}.
+ */
+ public static ConfigQuery<Set<String>> getTransitiveAreas() {
+ return config -> {
+ final Set<String> transitiveAreas = new HashSet<>();
+ config.query(getAreas()).forEach(s -> {
+ int index = s.lastIndexOf('.');
+ if (index < 0) {
+ transitiveAreas.add("<root>");
+ } else {
+ while (index > 0) {
+ s = s.substring(0, index);
+ transitiveAreas.add(s);
+ index = s.lastIndexOf('.');
+ }
+ }
+ });
+ return transitiveAreas;
+ };
+ }
+
+ /**
+ * Return a query to evaluate the set with all fully qualified area names, containing only the
+ * areas that match the predicate and have properties attached. This method should return the areas as accurate as possible,
+ * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
+ * does not support key iteration.
+ *
+ * @param predicate A predicate to deternine, which areas should be returned, not {@code null}.
+ * @return s set with all areas, never {@code null}.
+ */
+ public static ConfigQuery<Set<String>> getAreas(final Predicate<String> predicate) {
+ return config -> {
+ return config.query(getAreas()).stream().filter(predicate).collect(Collectors.toCollection(TreeSet::new));
+ };
+ }
+
+ /**
+ * Return a query to evaluate the set with all fully qualified area names, containing the transitive closure also including all
+ * subarea names, regardless if properties are accessible or not. This method should return the areas as accurate as possible,
+ * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
+ * does not support key iteration.
+ *
+ * @param predicate A predicate to deternine, which areas should be returned, not {@code null}.
+ * @return s set with all transitive areas, never {@code null}.
+ */
+ public static ConfigQuery<Set<String>> getTransitiveAreas(Predicate<String> predicate) {
+ return config -> {
+ return config.query(getTransitiveAreas()).stream().filter(predicate).collect(Collectors.toCollection(TreeSet::new));
+ };
+ }
+
+ /**
+ * Return a query to evaluate to evaluate if an area exists. In case where the underlying storage implementation does not allow
+ * querying the keys available, {@code false} should be returned.
+ *
+ * @param areaKey the configuration area (sub)path.
+ * @return {@code true}, if such a node exists.
+ */
+ public static ConfigQuery<Boolean> containsArea(String areaKey) {
+ return config -> {
+ return config.query(getAreas()).contains(areaKey);
+ };
+ }
+
+ /**
* Creates a ConfigOperator that creates a Configuration containing only keys
* that are contained in the given area (recursive). Hereby
* the area key is stripped away fromMap the resulting key.
@@ -106,7 +200,7 @@ public final class ConfigFunctions {
Map<String, String> area = new HashMap<>();
String lookupKey = areaKey + '.';
area.putAll(
- config.toMap().entrySet().stream()
+ config.getProperties().entrySet().stream()
.filter(e -> e.getKey().startsWith(lookupKey))
.collect(Collectors.toMap(
e -> stripKeys ? e.getKey().substring(areaKey.length() + 1) : e.getKey(),
@@ -120,13 +214,13 @@ public final class ConfigFunctions {
* that are contained in the given area (non recursive). Hereby
* the area key is stripped away fromMap the resulting key.
*
- * @param areaKey the area key, not null
+ * @param areaKey the area key, not null
* @param mappedAreaKey the target key, not null
* @return the area configuration, with the areaKey stripped away.
*/
public static UnaryOperator<Configuration> mapArea(String areaKey, String mappedAreaKey) {
- return mapKeys(key -> key.startsWith(areaKey + '.')?
- mappedAreaKey + key.substring(areaKey.length()):key);
+ return mapKeys(key -> key.startsWith(areaKey + '.') ?
+ mappedAreaKey + key.substring(areaKey.length()) : key);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java b/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
index b190b14..9104a1f 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
@@ -44,22 +44,22 @@ public final class ConfigurationBuilder {
/**
* Private singleton constructor.
*/
- private ConfigurationBuilder(MetaInfo metaInfo) {
- this.builderDelegate = PropertySourceBuilder.of(metaInfo);
+ private ConfigurationBuilder(String name) {
+ this.builderDelegate = PropertySourceBuilder.of(name);
}
/**
* Private singleton constructor.
*/
- private ConfigurationBuilder(String name) {
- this.builderDelegate = PropertySourceBuilder.of(name);
+ private ConfigurationBuilder(String name, PropertySource source) {
+ this.builderDelegate = PropertySourceBuilder.of(name, source);
}
/**
* Private singleton constructor.
*/
- private ConfigurationBuilder(PropertySource provider) {
- this.builderDelegate = PropertySourceBuilder.of(provider);
+ private ConfigurationBuilder(PropertySource source) {
+ this.builderDelegate = PropertySourceBuilder.of(source);
}
@@ -76,16 +76,6 @@ public final class ConfigurationBuilder {
/**
* Creates a new builder instance.
*
- * @param metaInfo the meta information, not null.
- * @return a new builder instance, never null.
- */
- public static ConfigurationBuilder of(MetaInfo metaInfo) {
- return new ConfigurationBuilder(metaInfo);
- }
-
- /**
- * Creates a new builder instance.
- *
* @param name the provider name, not null.
* @return a new builder instance, never null.
*/
@@ -120,11 +110,11 @@ public final class ConfigurationBuilder {
/**
* Sets the meta info to be used for the next operation.
*
- * @param metaInfo the meta info, not null.
+ * @param name the name, not null.
* @return the builder for chaining.
*/
- public ConfigurationBuilder withMetaInfo(MetaInfo metaInfo) {
- this.builderDelegate.withMetaInfo(metaInfo);
+ public ConfigurationBuilder withName(String name) {
+ this.builderDelegate.withName(name);
return this;
}
@@ -336,19 +326,6 @@ public final class ConfigurationBuilder {
}
/**
- * Sets an additional key on the final {@link org.apache.tamaya.MetaInfo} of the provider
- * created.
- *
- * @param key the key to be added, not null.
- * @param value the keys to be added, not null.
- * @return this builder for chaining
- */
- public ConfigurationBuilder setMeta(String key, String value){
- this.builderDelegate.setMeta(key, value);
- return this;
- }
-
- /**
* Build a new property provider based on the input.
* @return a new property provider, or null.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormat.java b/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormat.java
new file mode 100644
index 0000000..8feaf6a
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormat.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.config;
+
+import org.apache.tamaya.core.resource.Resource;
+import org.apache.tamaya.core.spi.ConfigurationFormatSpi;
+import org.apache.tamaya.spi.ServiceContext;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Implementations current this class encapsulate the mechanism how to read a
+ * resource URI including interpreting the format correctly (e.g. xml vs.
+ * properties).
+ */
+public interface ConfigurationFormat{
+
+ /**
+ * Returns a unique identifier that identifies each format.
+ *
+ * @return the unique format id, mever null.
+ */
+ public String getFormatName();
+
+ /**
+ * Check if the given {@link java.net.URI} and path xpression qualify that this format should be
+ * able to read them, e.g. checking for compatible file endings.
+ *
+ * @param resource the configuration location, not null
+ * @return {@code true} if the given resource is in a format supported by
+ * this instance.
+ */
+ boolean isAccepted(Resource resource);
+
+ /**
+ * Reads a {@link org.apache.tamaya.PropertySource} fromMap the given URI, using this format.
+ *
+ * @param resource the configuration location, not null
+ * @return the corresponding {@link java.util.Map}, never {@code null}.
+ */
+ Map<String,String> readConfiguration(Resource resource);
+
+ /**
+ * Access a {@link ConfigurationFormat}.
+ *
+ * @param formatName the format name
+ * @return the corresponding {@link ConfigurationFormat}, or {@code null}, if
+ * not available for the given environment.
+ */
+ public static ConfigurationFormat of(String formatName){
+ return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getFormat(formatName);
+ }
+
+ /**
+ * Get a collection current the keys current the registered {@link ConfigurationFormat} instances.
+ *
+ * @return a collection current the keys current the registered {@link ConfigurationFormat} instances.
+ */
+ public static Collection<String> getFormatNames(){
+ return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getFormatNames();
+ }
+
+ /**
+ * Evaluate the matching format for a given resource.
+ *
+ * @param resource The resource
+ * @return a matching configuration format, or {@code null} if no matching format could be determined.
+ */
+ public static ConfigurationFormat from(Resource resource){
+ return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getFormat(resource);
+
+ }
+
+ /**
+ * Get an instance for reading configuration fromMap a {@code .properties} file,
+ * as defined by {@link java.util.Properties#load(java.io.InputStream)}.
+ *
+ * @return a format instance for reading configuration fromMap a {@code .properties} file, never null.
+ */
+ public static ConfigurationFormat getPropertiesFormat(){
+ return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getPropertiesFormat();
+ }
+
+ /**
+ * Get an instance for reading configuration fromMap a {@code .xml} properties file,
+ * as defined by {@link java.util.Properties#loadFromXML(java.io.InputStream)}.
+ *
+ * @return a format instance for reading configuration fromMap a {@code .xml} properties file, never null.
+ */
+ public static ConfigurationFormat getXmlPropertiesFormat(){
+ return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getXmlPropertiesFormat();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormats.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormats.java b/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormats.java
deleted file mode 100644
index e2469ee..0000000
--- a/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormats.java
+++ /dev/null
@@ -1,91 +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.core.config;
-
-import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.spi.ConfigurationFormat;
-import org.apache.tamaya.core.spi.ConfigurationFormatsSingletonSpi;
-
-import org.apache.tamaya.spi.ServiceContext;
-
-import java.util.Collection;
-
-/**
- * Singleton accessor for accessing {@link org.apache.tamaya.core.spi.ConfigurationFormat} instances.
- */
-public final class ConfigurationFormats{
-
- /**
- * Private singleton constructor.
- */
- private ConfigurationFormats(){
- }
-
- /**
- * Access a {@link org.apache.tamaya.core.spi.ConfigurationFormat}.
- *
- * @param formatName the format name
- * @return the corresponding {@link org.apache.tamaya.core.spi.ConfigurationFormat}, or {@code null}, if
- * not available for the given environment.
- */
- public static ConfigurationFormat getFormat(String formatName){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatsSingletonSpi.class).getFormat(formatName);
- }
-
- /**
- * Get a collection current the keys current the registered {@link ConfigurationFormat} instances.
- *
- * @return a collection current the keys current the registered {@link ConfigurationFormat} instances.
- */
- public static Collection<String> getFormatNames(){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatsSingletonSpi.class).getFormatNames();
- }
-
- /**
- * Evaluate the matching format for a given resource.
- *
- * @param resource The resource
- * @return a matching configuration format, or {@code null} if no matching format could be determined.
- */
- public static ConfigurationFormat getFormat(Resource resource){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatsSingletonSpi.class).getFormat(resource);
-
- }
-
- /**
- * Get an instance for reading configuration fromMap a {@code .properties} file,
- * as defined by {@link java.util.Properties#load(java.io.InputStream)}.
- *
- * @return a format instance for reading configuration fromMap a {@code .properties} file, never null.
- */
- public static ConfigurationFormat getPropertiesFormat(){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatsSingletonSpi.class).getPropertiesFormat();
- }
-
- /**
- * Get an instance for reading configuration fromMap a {@code .xml} properties file,
- * as defined by {@link java.util.Properties#loadFromXML(java.io.InputStream)}.
- *
- * @return a format instance for reading configuration fromMap a {@code .xml} properties file, never null.
- */
- public static ConfigurationFormat getXmlPropertiesFormat(){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatsSingletonSpi.class).getXmlPropertiesFormat();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/config/FreezedConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/FreezedConfiguration.java b/core/src/main/java/org/apache/tamaya/core/config/FreezedConfiguration.java
index 7ecaf5d..240ccbe 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/FreezedConfiguration.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/FreezedConfiguration.java
@@ -34,16 +34,14 @@ final class FreezedConfiguration extends AbstractConfiguration implements Serial
private static final long serialVersionUID = -6373137316556444171L;
private PropertySource properties;
- private String version;
/**
* Constructor.
* @param config The base configuration.
*/
private FreezedConfiguration(Configuration config){
- super(MetaInfoBuilder.of(config.getMetaInfo()).set("freezedAt", Instant.now().toString()).build());
+ super(config.getName());
this.properties = PropertySourceBuilder.of(config).buildFreezed();
- this.version = Objects.requireNonNull(config.getVersion());
}
public static final Configuration of(Configuration config){
@@ -54,13 +52,8 @@ final class FreezedConfiguration extends AbstractConfiguration implements Serial
}
@Override
- public Map<String,String> toMap(){
- return properties.toMap();
- }
-
- @Override
- public String getVersion() {
- return version;
+ public Map<String,String> getProperties(){
+ return properties.getProperties();
}
@Override
@@ -71,14 +64,12 @@ final class FreezedConfiguration extends AbstractConfiguration implements Serial
FreezedConfiguration that = (FreezedConfiguration) o;
if (!properties.equals(that.properties)) return false;
- if (version != null ? !version.equals(that.version) : that.version != null) return false;
return true;
}
@Override
public int hashCode() {
int result = properties.hashCode();
- result = 31 * result + (version != null ? version.hashCode() : 0);
return result;
}
@@ -86,7 +77,7 @@ final class FreezedConfiguration extends AbstractConfiguration implements Serial
public String toString() {
return "FreezedConfiguration{" +
"properties=" + properties +
- ", version=" + version +
+ ", name=" + name +
'}';
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java b/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
index e668b91..b5a4a6a 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
@@ -27,15 +27,15 @@ class MappedConfiguration extends AbstractConfiguration implements Configuration
* @param keyMapper The mapping operator, not null
*/
public MappedConfiguration(Configuration config, UnaryOperator<String> keyMapper) {
- super(MetaInfoBuilder.of(config.getMetaInfo()).setInfo("Mapped configuration, mapper=" + keyMapper).build());
+ super(config.getName());
this.config = Objects.requireNonNull(config);
this.keyMapper = Objects.requireNonNull(keyMapper);
}
@Override
- public Map<String, String> toMap() {
+ public Map<String, String> getProperties() {
Map<String, String> result = new HashMap<>();
- Map<String, String> map = this.config.toMap();
+ Map<String, String> map = this.config.getProperties();
map.forEach((k,v) -> {
String targetKey = keyMapper.apply(k);
if(targetKey!=null){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/env/BuildableEnvironment.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/env/BuildableEnvironment.java b/core/src/main/java/org/apache/tamaya/core/env/BuildableEnvironment.java
deleted file mode 100644
index f44592c..0000000
--- a/core/src/main/java/org/apache/tamaya/core/env/BuildableEnvironment.java
+++ /dev/null
@@ -1,111 +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.core.env;
-
-import org.apache.tamaya.Environment;
-
-import java.util.*;
-
-/**
- * Environment class that is used by the {@link org.apache.tamaya.core.env.EnvironmentBuilder}.
- */
-class BuildableEnvironment implements Environment {
-
- /** The environment data. */
- private Map<String,String> context = new TreeMap<>();
-
- /**
- * Constructor.
- * @param builder the builder, not null.
- */
- BuildableEnvironment(EnvironmentBuilder builder){
- Objects.requireNonNull(builder);
- context.putAll(builder.contextData);
- }
-
- @Override
- public Map<String, String> toMap() {
- return context;
- }
-
- @Override
- public Optional<String> get(String key){
- return Optional.ofNullable(context.get(key));
- }
-
- @Override
- public boolean containsKey(String key){
- return context.containsKey(key);
- }
-
- @Override
- public Set<String> keySet() {
- return context.keySet();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- BuildableEnvironment that = (BuildableEnvironment) o;
- return context.equals(that.context);
- }
-
- @Override
- public int hashCode() {
- return context.hashCode();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString(){
- return "Environment: " + getData();
- }
-
- /**
- * Get the delta.
- * @return
- */
- private String getData() {
- StringBuilder b = new StringBuilder();
- for(Map.Entry<String,String> en: this.context.entrySet()){
- b.append(" ").append(en.getKey()).append('=').append(escape(en.getValue())).append('\n');
- }
- if(b.length()>0)
- b.setLength(b.length()-1);
- return b.toString();
- }
-
- /**
- * Escapes several characters.
- * @param value
- * @return
- */
- private String escape(String value){
- if(value==null)
- return null;
- return value.replaceAll("\n", "\\\\n").replaceAll("\r", "\\\\r").replaceAll("\t", "\\\\t")
- .replaceAll("=", "\\\\=");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/env/ConfiguredSystemProperties.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/env/ConfiguredSystemProperties.java b/core/src/main/java/org/apache/tamaya/core/env/ConfiguredSystemProperties.java
deleted file mode 100644
index 51367e8..0000000
--- a/core/src/main/java/org/apache/tamaya/core/env/ConfiguredSystemProperties.java
+++ /dev/null
@@ -1,353 +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.core.env;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import java.util.logging.Logger;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.Environment;
-
-/**
- * Properties implementation class that can be applied as current System properties by calling
- * {@link org.apache.tamaya.core.env.ConfiguredSystemProperties#install()}. The system properties will
- * then behave contextually depending on the current runtime configuration active.
- */
-public class ConfiguredSystemProperties extends Properties {
-
- private static final long serialVersionUID = 2152870929299226804L;
-
- private static final Logger LOG = Logger.getLogger(ConfiguredSystemProperties.class.getName());
- private Properties initialProperties;
- private static volatile Map<String, Properties> contextualProperties = new ConcurrentHashMap<>();
- private static volatile Supplier<String> contextProvider = () ->
- Environment.current().get("context.id").orElse("<system>");
-
-
- private final Object LOCK = new Object();
-
-
- private ConfiguredSystemProperties(Properties initialProperties) {
- super(initialProperties);
- this.initialProperties = initialProperties;
- }
-
- public static void install() {
- Properties props = System.getProperties();
- if (props instanceof ConfiguredSystemProperties) {
- return;
- }
- ConfiguredSystemProperties systemProps = new ConfiguredSystemProperties(props);
- LOG.finest("Installing enhanced system properties...");
- System.setProperties(systemProps);
- LOG.info("Installed enhanced system properties successfully.");
- }
-
- public static void uninstall() {
- Properties props = System.getProperties();
- if (props instanceof ConfiguredSystemProperties) {
- Properties initialProperties = ((ConfiguredSystemProperties) props).initialProperties;
- LOG.finest("Uninstalling enhanced system properties...");
- System.setProperties(initialProperties);
- LOG.info("Uninstalled enhanced system properties successfully.");
- }
- }
-
- @Override
- public String getProperty(String key) {
- return getContextualProperties().getProperty(key);
- }
-
- @Override
- public String getProperty(String key, String defaultValue) {
- return getContextualProperties().getProperty(key, defaultValue);
- }
-
- @Override
- public Enumeration<?> propertyNames() {
- return getContextualProperties().propertyNames();
- }
-
- @Override
- public Set<String> stringPropertyNames() {
- return getContextualProperties().stringPropertyNames();
- }
-
- @Override
- public synchronized int size() {
- return getContextualProperties().size();
- }
-
- @Override
- public synchronized Enumeration<Object> keys() {
- return getContextualProperties().keys();
- }
-
- @Override
- public synchronized Enumeration<Object> elements() {
- return getContextualProperties().elements();
- }
-
- @Override
- public synchronized boolean contains(Object value) {
- return getContextualProperties().contains(value);
- }
-
- @Override
- public boolean containsValue(Object value) {
- return getContextualProperties().containsValue(value);
- }
-
- @Override
- public synchronized boolean containsKey(Object key) {
- return getContextualProperties().containsKey(key);
- }
-
- @Override
- public synchronized Object get(Object key) {
- return getContextualProperties().get(key);
- }
-
- @Override
- public synchronized Object clone() {
- return getContextualProperties().clone();
- }
-
- @Override
- public Set<Object> keySet() {
- return getContextualProperties().keySet();
- }
-
- @Override
- public Set<Map.Entry<Object, Object>> entrySet() {
- return getContextualProperties().entrySet();
- }
-
- @Override
- public Collection<Object> values() {
- return getContextualProperties().values();
- }
-
-
- @Override
- public Object getOrDefault(Object key, Object defaultValue) {
- return getContextualProperties().getOrDefault(key, defaultValue);
- }
-
- @Override
- public void forEach(BiConsumer<? super Object, ? super Object> action) {
- getContextualProperties().forEach(action);
- }
-
-
- @Override
- public Object computeIfAbsent(Object key, Function<? super Object, ?> mappingFunction) {
- return getContextualProperties().computeIfAbsent(key, mappingFunction);
- }
-
- @Override
- public synchronized Object computeIfPresent(Object key, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
- return getContextualProperties().computeIfPresent(key, remappingFunction);
- }
-
- @Override
- public synchronized Object compute(Object key, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
- return getContextualProperties().compute(key, remappingFunction);
- }
-
- @Override
- public String toString() {
- return getContextualProperties().toString();
- }
-
- @Override
- public synchronized Object setProperty(String key, String value) {
- return getContextualProperties().setProperty(key, value);
- }
-
- @Override
- public synchronized void load(Reader reader) throws IOException {
- getContextualProperties().load(reader);
- }
-
- @Override
- public synchronized void load(InputStream inStream) throws IOException {
- getContextualProperties().load(inStream);
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public void save(OutputStream out, String comments) {
- super.save(out, comments);
- }
-
- @Override
- public void store(Writer writer, String comments) throws IOException {
- getContextualProperties().store(writer, comments);
- }
-
- @Override
- public void store(OutputStream out, String comments) throws IOException {
- getContextualProperties().store(out, comments);
- }
-
- @Override
- public void loadFromXML(InputStream in) throws IOException {
- getContextualProperties().loadFromXML(in);
- }
-
- @Override
- public void storeToXML(OutputStream os, String comment) throws IOException {
- getContextualProperties().storeToXML(os, comment);
- }
-
- @Override
- public void storeToXML(OutputStream os, String comment, String encoding) throws IOException {
- getContextualProperties().storeToXML(os, comment, encoding);
- }
-
- @Override
- public void list(PrintStream out) {
- getContextualProperties().list(out);
- }
-
- @Override
- public void list(PrintWriter out) {
- getContextualProperties().list(out);
- }
-
- @Override
- public boolean isEmpty() {
- return getContextualProperties().isEmpty();
- }
-
- @Override
- public Object put(Object key, Object value) {
- return getContextualProperties().put(key, value);
- }
-
- @Override
- public Object remove(Object key) {
- return getContextualProperties().remove(key);
- }
-
- @Override
- public void putAll(Map<?, ?> t) {
- getContextualProperties().putAll(t);
- }
-
- @Override
- public void clear() {
- getContextualProperties().clear();
- }
-
- @Override
- public boolean equals(Object o) {
- return getContextualProperties().equals(o);
- }
-
- @Override
- public int hashCode() {
- return getContextualProperties().hashCode();
- }
-
- @Override
- public void replaceAll(BiFunction<? super Object, ? super Object, ?> function) {
- getContextualProperties().replaceAll(function);
- }
-
- @Override
- public Object putIfAbsent(Object key, Object value) {
- return getContextualProperties().putIfAbsent(key, value);
- }
-
- @Override
- public boolean remove(Object key, Object value) {
- return getContextualProperties().remove(key, value);
- }
-
- @Override
- public boolean replace(Object key, Object oldValue, Object newValue) {
- return getContextualProperties().replace(key, oldValue, newValue);
- }
-
- @Override
- public Object replace(Object key, Object value) {
- return getContextualProperties().replace(key, value);
- }
-
- @Override
- public Object merge(Object key, Object value, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
- return getContextualProperties().merge(key, value, remappingFunction);
- }
-
- public Properties getInitialProperties() {
- return initialProperties;
- }
-
- /**
- * Uninstalls the contextual system properties for the current context, as determined by the current
- * context provider active.
- */
- public static void resetProperties() {
- String contextId = contextProvider == null ? "" : contextProvider.get();
- contextualProperties.remove(contextId);
- }
-
- protected Properties getContextualProperties() {
- String contextId = contextProvider == null ? "" : contextProvider.get();
- Properties props = ConfiguredSystemProperties.contextualProperties.get(contextId);
- if (props == null) {
- synchronized (LOCK) {
- props = ConfiguredSystemProperties.contextualProperties.get(contextId);
- if (props == null) {
- props = createNewProperties();
- contextualProperties.put(contextId, props);
- }
- }
- }
- return props;
- }
-
- protected Properties createNewProperties() {
- Properties props = new Properties(initialProperties);
- Configuration config = Configuration.current();
- Map<String, String> configMap = config.toMap();
- for (Map.Entry<String, String> en : configMap.entrySet()) {
- props.put(en.getKey(), en.getValue());
- }
- return props;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/env/EnvironmentBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/env/EnvironmentBuilder.java b/core/src/main/java/org/apache/tamaya/core/env/EnvironmentBuilder.java
deleted file mode 100644
index 895ac76..0000000
--- a/core/src/main/java/org/apache/tamaya/core/env/EnvironmentBuilder.java
+++ /dev/null
@@ -1,99 +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.core.env;
-
-import org.apache.tamaya.Environment;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-/**
-* Builder to create new {@link org.apache.tamaya.Environment instances.}
-*/
-public final class EnvironmentBuilder{
-
- /** The property name for the stage property. */
- public static final String STAGE_PROP = "stage";
-
- /** THe environment data. */
- Map<String,String> contextData = new HashMap<>();
-
- /**
- * Constructor.
- */
- private EnvironmentBuilder() {
- }
-
- /**
- * Creates a new buildr instance.
- * @return the new builder instance.
- */
- public static final EnvironmentBuilder of() {
- return new EnvironmentBuilder();
- }
-
- /**
- * Sets a new environment property.
- * @param key the key, not null.
- * @param value the keys, not null.
- * @return the builder for chaining
- */
- public EnvironmentBuilder set(String key, String value){
- this.contextData.put(key, value);
- return this;
- }
-
- /**
- * Sets new environment properties.
- * @param values the key/values, not null.
- * @return the builder for chaining
- */
- public EnvironmentBuilder setAll(Map<String,String> values){
- this.contextData.putAll(values);
- return this;
- }
-
- /**
- * Sets the stage using the default stage key.
- * @param stage The stage, not null.
- * @return the builder for chaining.
- */
- public EnvironmentBuilder setStage(String stage){
- this.contextData.put(STAGE_PROP, Objects.requireNonNull(stage));
- return this;
- }
-
- /**
- * Access a property
- * @param key the key, not null.
- * @return the builder for chaining.
- */
- public String getProperty(String key) {
- return this.contextData.get(key);
- }
-
- /**
- * Builds a new Environment.
- * @return a new Environment, never null.
- */
- public Environment build() {
- return new BuildableEnvironment(this);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/MetaConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/MetaConfig.java b/core/src/main/java/org/apache/tamaya/core/internal/MetaConfig.java
index 6a98fb8..4b3511f 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/MetaConfig.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/MetaConfig.java
@@ -18,10 +18,9 @@
*/
package org.apache.tamaya.core.internal;
-import org.apache.tamaya.core.config.ConfigurationFormats;
import org.apache.tamaya.core.resource.Resource;
import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.core.spi.ConfigurationFormat;
+import org.apache.tamaya.core.config.ConfigurationFormat;
import org.apache.tamaya.core.resource.ResourceLoader;
@@ -49,7 +48,7 @@ public final class MetaConfig {
"classpath:META-INF/config.properties");
for(Resource res:resources){
try{
- ConfigurationFormat format = ConfigurationFormats.getFormat(res);
+ ConfigurationFormat format = ConfigurationFormat.from(res);
Map<String,String> read = format.readConfiguration(res);
properties.putAll(read);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultCodecSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultCodecSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultCodecSpi.java
new file mode 100644
index 0000000..fbbf130
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultCodecSpi.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.config;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneId;
+import java.util.Currency;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+
+import org.apache.tamaya.Codec;
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.annotation.WithCodec;
+import org.apache.tamaya.spi.CodecSpi;
+
+/**
+ * Default codecs singleton, which provides default codesc for all kind of classes out of the box, which will be
+ * instantiatable from configuration, if one of the following is given:
+ * <ul>
+ * <li>static factory methods using a String as simgle argument, called {@code of, valueOf, getInstance, instance, parse}</li>
+ * <li>have constructors taking a single String</li>
+ * </ul>
+ */
+@SuppressWarnings({"rawtypes", "unchecked"})
+public class DefaultCodecSpi implements CodecSpi {
+
+
+ private Map<Class,Codec> adapters = new ConcurrentHashMap<>();
+
+ public DefaultCodecSpi(){
+ // Add default adapters
+ register(char.class, (s) -> s.charAt(0), (ch) -> String.valueOf(ch));
+ register(byte.class, Byte::parseByte, Object::toString);
+ register(short.class, Short::parseShort, Object::toString);
+ register(int.class, Integer::parseInt, Object::toString);
+ register(long.class, Long::parseLong, Object::toString);
+ register(boolean.class, Boolean::parseBoolean, b -> String.valueOf(b));
+ register(float.class, Float::parseFloat, f -> String.valueOf(f));
+ register(double.class, Double::parseDouble, d -> String.valueOf(d));
+
+ register(Character.class, (s) -> s.charAt(0), Object::toString);
+ register(Byte.class, Byte::valueOf, Object::toString);
+ register(Short.class, Short::valueOf, String::valueOf);
+ register(Integer.class, Integer::valueOf, Object::toString);
+ register(Long.class, Long::valueOf, Object::toString);
+ register(Boolean.class, Boolean::valueOf, b -> String.valueOf(b));
+ register(Float.class, Float::valueOf, f -> String.valueOf(f));
+ register(Double.class, Double::valueOf, d -> String.valueOf(d));
+ register(BigDecimal.class, BigDecimal::new, String::valueOf);
+ register(BigInteger.class, BigInteger::new, String::valueOf);
+
+ register(Currency.class, Currency::getInstance, Object::toString);
+
+ register(LocalDate.class, LocalDate::parse, Object::toString);
+ register(LocalTime.class, LocalTime::parse, Object::toString);
+ register(LocalDateTime.class, LocalDateTime::parse, Object::toString);
+ register(ZoneId.class, ZoneId::of, ZoneId::getId);
+ }
+
+ @Override
+ public <T> Codec<T> register(Class<T> targetType, Codec<T> adapter){
+ return adapters.put(targetType, adapter);
+ }
+
+ @Override
+ public <T> Codec<T> getCodec(Class<T> targetType, WithCodec adapterAnnot){
+ Codec codec = null;
+ Class<? extends Codec> configuredCodec = null;
+ if(adapterAnnot != null){
+ configuredCodec = adapterAnnot.value();
+ if(!configuredCodec.equals(Codec.class)){
+ try{
+ codec = configuredCodec.newInstance();
+ }
+ catch(Exception e){
+ throw new ConfigException("Invalid codec configured.", e);
+ }
+ }
+ }
+ if(codec == null){
+ codec = adapters.get(targetType);
+ }
+ if(codec == null){
+ codec = getDefaultCodec(targetType);
+ }
+ if(codec == null){
+ throw new ConfigException("No Codec found for " + targetType.getName());
+ }
+ return codec;
+ }
+
+ private <T> Codec getDefaultCodec(Class<T> targetType) {
+ Function<String, T> decoder = null;
+ Method factoryMethod = getFactoryMethod(targetType, "of", "valueOf", "instanceOf", "getInstance", "from", "parse");
+ if(factoryMethod!=null){
+ decoder = (s) -> {
+ try{
+ factoryMethod.setAccessible(true);
+ return targetType.cast(factoryMethod.invoke(s));
+ }
+ catch (Exception e){
+ throw new ConfigException("Failed to decode '"+s+"'", e);
+ }
+ };
+ }
+ if(decoder==null) {
+ try {
+ Constructor<T> constr = targetType.getDeclaredConstructor(String.class);
+ decoder = (s) -> {
+ try{
+ constr.setAccessible(true);
+ return constr.newInstance(s);
+ }
+ catch (Exception e){
+ throw new ConfigException("Failed to decode '"+s+"'", e);
+ }
+ };
+ } catch (Exception e) {
+ // ignore, TODO log finest
+ }
+ }
+ if(decoder!=null) {
+ return register(targetType, decoder, String::valueOf);
+ }
+ return null;
+ }
+
+ private Method getFactoryMethod(Class<?> type, String... methodNames) {
+ Method m;
+ for(String name:methodNames){
+ try{
+ m = type.getDeclaredMethod(name, String.class);
+ return m;
+ }
+ catch(Exception e){
+ // ignore, TODO log finest
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isTargetTypeSupported(Class<?> targetType){
+ return adapters.containsKey(targetType);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
deleted file mode 100644
index 2b0a471..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
+++ /dev/null
@@ -1,136 +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.core.internal.config;
-
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Consumer;
-import java.util.function.Predicate;
-
-import org.apache.tamaya.ConfigChangeSet;
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertySource;
-import org.apache.tamaya.core.internal.el.DefaultExpressionEvaluator;
-import org.apache.tamaya.core.internal.inject.ConfigTemplateInvocationHandler;
-import org.apache.tamaya.core.internal.inject.ConfigurationInjector;
-import org.apache.tamaya.core.internal.inject.WeakConfigListenerManager;
-import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
-import org.apache.tamaya.core.spi.ExpressionEvaluator;
-import org.apache.tamaya.spi.ConfigurationManagerSingletonSpi;
-import org.apache.tamaya.spi.ServiceContext;
-
-
-/**
- * Default SPI that implements the behaviour of {@link org.apache.tamaya.spi.ConfigurationManagerSingletonSpi}.
- */
-@SuppressWarnings("unchecked")
-public class DefaultConfigurationManagerSingletonSpi implements ConfigurationManagerSingletonSpi {
-
- private static final String DEFAULT_CONFIG_NAME = "default";
-
- private Map<String, ConfigurationProviderSpi> configProviders = new ConcurrentHashMap<>();
-
- private ExpressionEvaluator expressionEvaluator = loadEvaluator();
-
- private ExpressionEvaluator loadEvaluator() {
- ExpressionEvaluator eval = ServiceContext.getInstance().getService(ExpressionEvaluator.class).orElse(null);
- if (eval == null) {
- eval = new DefaultExpressionEvaluator();
- }
- return eval;
- }
-
- public DefaultConfigurationManagerSingletonSpi() {
- for (ConfigurationProviderSpi spi : ServiceContext.getInstance().getServices(ConfigurationProviderSpi.class, Collections.emptyList())) {
- configProviders.put(spi.getConfigName(), spi);
- }
- }
-
- @Override
- public <T> T createTemplate(Class<T> type, Configuration... configurations) {
- ClassLoader cl = Optional.ofNullable(Thread.currentThread()
- .getContextClassLoader()).orElse(getClass().getClassLoader());
- return (T) Proxy.newProxyInstance(cl, new Class[]{type}, new ConfigTemplateInvocationHandler(type, configurations));
- }
-
- /**
- *
- * @param instance the instance with configuration annotations, not null.
- * @param configurations the configurations to be used for evaluating the values for injection into {@code instance}.
- * If no items are passed, the default configuration is used.
- */
- @Override
- public void configure(Object instance, Configuration... configurations) {
- ConfigurationInjector.configure(instance, configurations);
- }
-
-
- @Override
- public String evaluateValue(String expression, Configuration... configurations) {
- return expressionEvaluator.evaluate(expression, configurations);
- }
-
- @Override
- public void addChangeListener(Consumer<ConfigChangeSet> l) {
- WeakConfigListenerManager.of().registerConsumer(l,l);
- }
-
- @Override
- public void removeChangeListener(Consumer<ConfigChangeSet> l) {
- WeakConfigListenerManager.of().unregisterConsumer(l);
- }
-
- @Override
- public void publishChange(ConfigChangeSet configChangeSet) {
- WeakConfigListenerManager.of().publishChangeEvent(configChangeSet);
- }
-
- @Override
- public boolean isConfigurationDefined(String name) {
- ConfigurationProviderSpi spi = this.configProviders.get(name);
- return spi != null;
- }
-
- @Override
- public Configuration getConfiguration(String name) {
- ConfigurationProviderSpi provider = configProviders.get(name);
- if (provider == null) {
- if (DEFAULT_CONFIG_NAME.equals(name)) {
- provider = new FallbackSimpleConfigProvider();
- configProviders.put(DEFAULT_CONFIG_NAME, provider);
- } else {
- throw new ConfigException("No such config: " + name);
- }
- }
- Configuration config = provider.getConfiguration();
- if (config == null) {
- throw new ConfigException("No such config: " + name);
- }
- return config;
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java
new file mode 100644
index 0000000..f755058
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.config;
+
+import java.lang.reflect.Proxy;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Consumer;
+
+import org.apache.tamaya.ConfigChangeSet;
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.core.internal.el.DefaultExpressionEvaluator;
+import org.apache.tamaya.core.internal.inject.ConfigTemplateInvocationHandler;
+import org.apache.tamaya.core.internal.inject.ConfigurationInjector;
+import org.apache.tamaya.core.internal.inject.WeakConfigListenerManager;
+import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
+import org.apache.tamaya.core.spi.ExpressionEvaluator;
+import org.apache.tamaya.spi.ConfigurationSpi;
+import org.apache.tamaya.spi.ServiceContext;
+
+
+/**
+ * Default SPI that implements the behaviour of {@link org.apache.tamaya.spi.ConfigurationSpi}.
+ */
+@SuppressWarnings("unchecked")
+public class DefaultConfigurationSpi implements ConfigurationSpi {
+
+ private static final String DEFAULT_CONFIG_NAME = "default";
+
+ private Map<String, ConfigurationProviderSpi> configProviders = new ConcurrentHashMap<>();
+
+ private ExpressionEvaluator expressionEvaluator = loadEvaluator();
+
+ private ExpressionEvaluator loadEvaluator() {
+ ExpressionEvaluator eval = ServiceContext.getInstance().getService(ExpressionEvaluator.class).orElse(null);
+ if (eval == null) {
+ eval = new DefaultExpressionEvaluator();
+ }
+ return eval;
+ }
+
+ public DefaultConfigurationSpi() {
+ for (ConfigurationProviderSpi spi : ServiceContext.getInstance().getServices(ConfigurationProviderSpi.class, Collections.emptyList())) {
+ configProviders.put(spi.getConfigName(), spi);
+ }
+ }
+
+ @Override
+ public <T> T createTemplate(Class<T> type, Configuration... configurations) {
+ ClassLoader cl = Optional.ofNullable(Thread.currentThread()
+ .getContextClassLoader()).orElse(getClass().getClassLoader());
+ return (T) Proxy.newProxyInstance(cl, new Class[]{type}, new ConfigTemplateInvocationHandler(type, configurations));
+ }
+
+ /**
+ *
+ * @param instance the instance with configuration annotations, not null.
+ * @param configurations the configurations to be used for evaluating the values for injection into {@code instance}.
+ * If no items are passed, the default configuration is used.
+ */
+ @Override
+ public void configure(Object instance, Configuration... configurations) {
+ ConfigurationInjector.configure(instance, configurations);
+ }
+
+
+ @Override
+ public String evaluateValue(String expression, Configuration... configurations) {
+ return expressionEvaluator.evaluate(expression, configurations);
+ }
+
+ @Override
+ public void addChangeListener(Consumer<ConfigChangeSet> l) {
+ WeakConfigListenerManager.of().registerConsumer(l,l);
+ }
+
+ @Override
+ public void removeChangeListener(Consumer<ConfigChangeSet> l) {
+ WeakConfigListenerManager.of().unregisterConsumer(l);
+ }
+
+ @Override
+ public void publishChange(ConfigChangeSet configChangeSet) {
+ WeakConfigListenerManager.of().publishChangeEvent(configChangeSet);
+ }
+
+ @Override
+ public boolean isConfigurationAvailable(String name) {
+ ConfigurationProviderSpi spi = this.configProviders.get(name);
+ return spi != null;
+ }
+
+ @Override
+ public Configuration getConfiguration(String name) {
+ ConfigurationProviderSpi provider = configProviders.get(name);
+ if (provider == null) {
+ if (DEFAULT_CONFIG_NAME.equals(name)) {
+ provider = new FallbackSimpleConfigProvider();
+ configProviders.put(DEFAULT_CONFIG_NAME, provider);
+ } else {
+ throw new ConfigException("No such config: " + name);
+ }
+ }
+ Configuration config = provider.getConfiguration();
+ if (config == null) {
+ throw new ConfigException("No such config: " + name);
+ }
+ return config;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/config/FileConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/FileConfiguration.java b/core/src/main/java/org/apache/tamaya/core/internal/config/FileConfiguration.java
index 0b5c2c7..661bf64 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/FileConfiguration.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/FileConfiguration.java
@@ -3,6 +3,7 @@ package org.apache.tamaya.core.internal.config;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
+import java.util.UUID;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.MetaInfo;
@@ -27,18 +28,13 @@ class FileConfiguration implements Configuration, FileChangeObserver {
return Optional.ofNullable(configurationMap.get(key));
}
- @Override
- public MetaInfo getMetaInfo() {
- return MetaInfo.of("files.config");
- }
-
- @Override
- public boolean containsKey(String key) {
- return configurationMap.containsKey(key);
+ @Override
+ public String getName() {
+ return "files.config";
}
@Override
- public Map<String, String> toMap() {
+ public Map<String, String> getProperties() {
return configurationMap;
}
@@ -66,7 +62,7 @@ class FileConfiguration implements Configuration, FileChangeObserver {
}
if(Configuration.class.isInstance(obj)) {
Configuration other = Configuration.class.cast(obj);
- return Objects.equals(configurationMap, other.toMap());
+ return Objects.equals(configurationMap, other.getProperties());
}
return false;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentApplicationEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentApplicationEnvironmentProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentApplicationEnvironmentProvider.java
deleted file mode 100644
index 1632fcd..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentApplicationEnvironmentProvider.java
+++ /dev/null
@@ -1,101 +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.core.internal.env;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.tamaya.core.config.ConfigurationFormats;
-import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.resource.ResourceLoader;
-import org.apache.tamaya.core.spi.ConfigurationFormat;
-import org.apache.tamaya.core.spi.EnvironmentProvider;
-import org.apache.tamaya.spi.ServiceContext;
-
-/**
- * Application environment provider that is dependent on the current context classloader and tries to
- * evaluate {@code META-INF/env/application.properties, META-INF/env/application.xml and META-INF/env/application.ini}.
- * Only if a property named {@code org.apache.tamaya.env.applicationId} is found, it will
- * be used as the {@code environmentId} and a corresponding {@link org.apache.tamaya.Environment} instance
- * is created and attached.
- */
-public class ClassLoaderDependentApplicationEnvironmentProvider implements EnvironmentProvider {
-
- private static final Logger LOG = Logger.getLogger(ClassLoaderDependentApplicationEnvironmentProvider.class.getName());
-
- private Map<ClassLoader, Map<String,String>> environments = new ConcurrentHashMap<>();
- private Map<ClassLoader, Boolean> environmentAvailable = new ConcurrentHashMap<>();
-
- @Override
- public boolean isActive() {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if(cl==null){
- return false;
- }
- Boolean available = this.environmentAvailable.get(cl);
- if(available!=null && !available){
- return false;
- }
- List<Resource> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
- "classpath:META-INF/env/application.properties", "classpath:META-INF/env/application.xml", "classpath:META-INF/env/application.ini");
- available = !propertyUris.isEmpty();
- this.environmentAvailable.put(cl, available);
- return available;
- }
-
- @Override
- public Map<String,String> getEnvironmentData() {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if(cl==null){
- return null;
- }
- Map<String,String> data = this.environments.get(cl);
- if(data!=null){
- return data;
- }
- List<Resource> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
- "classpath:META-INF/env/application.properties", "classpath:META-INF/env/application.xml", "classpath:META-INF/env/application.ini");
- data = new HashMap<>();
-
- for(Resource resource:propertyUris){
- try{
- ConfigurationFormat format = ConfigurationFormats.getFormat(resource);
- data.putAll(format.readConfiguration(resource));
- }
- catch(Exception e){
- LOG.log(Level.SEVERE, e, () -> "Error reading application environment data fromMap " + resource);
- }
- }
- data.put("classloader.type", cl.getClass().getName());
- data.put("classloader.info", cl.toString());
- Set<Resource> uris = new HashSet<>();
- uris.addAll(propertyUris);
- data.put("environment.sources", uris.toString());
- data = Collections.unmodifiableMap(data);
- this.environments.put(cl, data);
- return data;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentEarEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentEarEnvironmentProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentEarEnvironmentProvider.java
deleted file mode 100644
index 990d13d..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentEarEnvironmentProvider.java
+++ /dev/null
@@ -1,108 +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.core.internal.env;
-
-import org.apache.tamaya.core.config.ConfigurationFormats;
-import org.apache.tamaya.core.env.EnvironmentBuilder;
-import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.core.spi.ConfigurationFormat;
-import org.apache.tamaya.core.spi.EnvironmentProvider;
-import org.apache.tamaya.core.resource.ResourceLoader;
-
-
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * This class implements a {@link org.apache.tamaya.core.spi.EnvironmentProvider} that tries
- * to read configuration for an ear deployment located under {@code META-INF/env/ear.properties,
- * META-INF/env/ear.xml or META-INF/env/ear.ini}. The environment id hereby is defined by a
- * configuration entry named {@code org.apache.tamaya.core.env.earId}.
- *
- * Only if such a configuration with such an {@code earId} is found an {@link org.apache.tamaya.Environment}
- * is created and attached to the corresponding ear classloader.
- */
-public class ClassLoaderDependentEarEnvironmentProvider implements EnvironmentProvider {
-
- private static final Logger LOG = Logger.getLogger(ClassLoaderDependentEarEnvironmentProvider.class.getName());
-
-// private static final String EARID_PROP = "environment.earId";
-
- private Map<ClassLoader, Map<String,String>> environments = new ConcurrentHashMap<>();
- private Map<ClassLoader, Boolean> environmentAvailable = new ConcurrentHashMap<>();
-
- @Override
- public boolean isActive() {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if(cl==null){
- return false;
- }
- Boolean available = this.environmentAvailable.get(cl);
- if(available!=null && !available){
- return false;
- }
- List<Resource> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
- "classpath:META-INF/env/ear.properties", "classpath:META-INF/env/ear.xml", "classpath:META-INF/env/ear.ini");
- available = !propertyUris.isEmpty();
- this.environmentAvailable.put(cl, available);
- return available;
- }
-
- @Override
- public Map<String,String> getEnvironmentData() {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if(cl==null){
- return null;
- }
- Map<String,String> data = this.environments.get(cl);
- if(data!=null){
- return data;
- }
- List<Resource> resources = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
- "classpath:META-INF/env/ear.properties", "classpath:META-INF/env/ear.xml", "classpath:META-INF/env/ear.ini");
- data = new HashMap<>();
- for(Resource resource:resources){
- try{
- ConfigurationFormat format = ConfigurationFormats.getFormat(resource);
- Map<String,String> read = format.readConfiguration(resource);
- data.putAll(read);
- }
- catch(Exception e){
- LOG.log(Level.SEVERE, e, () -> "Error reading ear environment data fromMap " + resource);
- }
- }
-// String earId = data.getOrDefault(EARID_PROP, cl.toString());
- String stageValue = data.get(EnvironmentBuilder.STAGE_PROP);
- if (stageValue != null) {
- data.put(EnvironmentBuilder.STAGE_PROP,stageValue);
- }
- data.put("classloader.type", cl.getClass().getName());
- data.put("classloader.info", cl.toString());
- Set<Resource> resourceSet = new HashSet<>();
- resourceSet.addAll(resources);
- data.put("environment.sources", resourceSet.toString());
- data = Collections.unmodifiableMap(data);
- this.environments.put(cl, data);
- return data;
- }
-
-}
[4/6] incubator-tamaya git commit: TAMAYA-19: - Moved out much of
unused/experimental code. - Reduced API (removing package private singletons)
- Aligned PropertySource with Deltaspike (mostly). - Moved Environment model
to separate metamodel module.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/env/InitialEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/env/InitialEnvironmentProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/env/InitialEnvironmentProvider.java
deleted file mode 100644
index c2e4704..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/env/InitialEnvironmentProvider.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.env;
-
-import java.net.InetAddress;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.TimeZone;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.tamaya.core.env.ConfiguredSystemProperties;
-import org.apache.tamaya.core.env.EnvironmentBuilder;
-import org.apache.tamaya.core.spi.EnvironmentProvider;
-
-/**
- * Default {@link org.apache.tamaya.Environment}.
- */
-public final class InitialEnvironmentProvider implements EnvironmentProvider{
-
- private Map<String,String> environmentData = new HashMap<>();
-
- public InitialEnvironmentProvider() {
- Properties props = System.getProperties();
- if(props instanceof ConfiguredSystemProperties){
- props = ((ConfiguredSystemProperties)props).getInitialProperties();
- }
- String stageValue = props.getProperty(EnvironmentBuilder.STAGE_PROP);
- environmentData.put(EnvironmentBuilder.STAGE_PROP, stageValue);
- environmentData.put("timezone", TimeZone.getDefault().getID());
- environmentData.put("locale", Locale.getDefault().toString());
- try {
- environmentData.put("host", InetAddress.getLocalHost().toString());
- } catch (Exception e) {
- Logger.getLogger(getClass().getName()).log(Level.WARNING, e, () -> "Failed to evaluate hostname.");
- }
- // Copy env properties....
- for (Entry<String, String> en : System.getenv().entrySet()) {
- environmentData.put(en.getKey(), en.getValue());
- }
- environmentData = Collections.unmodifiableMap(environmentData);
- }
-
- @Override
- public boolean isActive(){
- return true;
- }
-
- @Override
- public Map<String,String> getEnvironmentData() {
- return environmentData;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/env/SingleEnvironmentManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/env/SingleEnvironmentManager.java b/core/src/main/java/org/apache/tamaya/core/internal/env/SingleEnvironmentManager.java
deleted file mode 100644
index 4a75fbb..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/env/SingleEnvironmentManager.java
+++ /dev/null
@@ -1,70 +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.core.internal.env;
-
-import org.apache.tamaya.Environment;
-
-import org.apache.tamaya.core.env.EnvironmentBuilder;
-import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.spi.EnvironmentManagerSingletonSpi;
-import org.apache.tamaya.core.spi.EnvironmentProvider;
-
-import java.util.*;
-
-/**
- * Service for accessing {@link org.apache.tamaya.Environment}. Environments are used to
- * access/determine configurations.<br/>
- * <h3>Implementation PropertyMapSpec</h3> This class is
- * <ul>
- * <li>thread safe,
- * <li>and behaves contextual.
- * </ul>
- */
-public class SingleEnvironmentManager implements EnvironmentManagerSingletonSpi{
-
- private final List<EnvironmentProvider> environmentProviders = loadEnvironmentProviders();
- private Environment rootEnvironment = getCurrentEnvironment();
-
- private List<EnvironmentProvider> loadEnvironmentProviders() {
- List<EnvironmentProvider> providerList = new ArrayList<>();
- for(EnvironmentProvider prov: ServiceContext.getInstance().getServices(EnvironmentProvider.class)){
- providerList.add(prov);
- }
- return providerList;
- }
-
- @Override
- public Environment getCurrentEnvironment(){
- EnvironmentBuilder b = EnvironmentBuilder.of();
- for(EnvironmentProvider prov: environmentProviders){
- if(prov.isActive()){
- if(prov.isActive()){
- b.setAll(prov.getEnvironmentData());
- }
- }
- }
- return b.build();
- }
-
- @Override
- public Environment getRootEnvironment(){
- return rootEnvironment;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/env/SystemClassLoaderEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/env/SystemClassLoaderEnvironmentProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/env/SystemClassLoaderEnvironmentProvider.java
deleted file mode 100644
index b939017..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/env/SystemClassLoaderEnvironmentProvider.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.env;
-
-import org.apache.tamaya.core.config.ConfigurationFormats;
-import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.core.spi.ConfigurationFormat;
-import org.apache.tamaya.core.spi.EnvironmentProvider;
-import org.apache.tamaya.core.resource.ResourceLoader;
-
-
-import java.util.*;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * System environment provider (loaded only once using the system class loader) that loads additional environment properties fromMap the classpath evaluating
- * {@code META-INF/env/system.properties, META-INF/env/system.xml and META-INF/env/system.ini}.
- */
-public class SystemClassLoaderEnvironmentProvider implements EnvironmentProvider {
-
- private static final Logger LOG = Logger.getLogger(SystemClassLoaderEnvironmentProvider.class.getName());
-
- private Map<String,String> data = new HashMap<>();
-
-
- public SystemClassLoaderEnvironmentProvider(){
- List<Resource> propertyResources = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(ClassLoader.getSystemClassLoader(),
- "classpath:META-INF/env/system.properties", "classpath:META-INF/env/system.xml", "classpath:META-INF/env/system.ini");
- for(Resource resource:propertyResources){
- try{
- ConfigurationFormat format = ConfigurationFormats.getFormat(resource);
- Map<String,String> data = format.readConfiguration(resource);
- data.putAll(data);
- }
- catch(Exception e){
- LOG.log(Level.INFO, e, () -> "Could not read environment data from " + resource);
- }
- }
- data.put("classloader.type", ClassLoader.getSystemClassLoader().getClass().getName());
- data.put("classloader.info", ClassLoader.getSystemClassLoader().toString());
- Set<Resource> resourceSet = new HashSet<>();
- resourceSet.addAll(propertyResources);
- data.put("environment.system.sources", resourceSet.toString());
- this.data = Collections.unmodifiableMap(data);
- }
- @Override
- public boolean isActive() {
- return true;
- }
-
- @Override
- public Map<String,String> getEnvironmentData() {
- return data;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigFormatsSingletonSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigFormatsSingletonSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigFormatsSingletonSpi.java
deleted file mode 100644
index 0bf5728..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigFormatsSingletonSpi.java
+++ /dev/null
@@ -1,78 +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.core.internal.format;
-
-import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.spi.ConfigurationFormat;
-import org.apache.tamaya.core.spi.ConfigurationFormatsSingletonSpi;
-
-import java.util.*;
-import java.util.stream.Collectors;
-
-import org.apache.tamaya.spi.ServiceContext;
-
-/**
- * Singleton accessor to access registered reader mechanism.
- */
-public final class DefaultConfigFormatsSingletonSpi implements ConfigurationFormatsSingletonSpi{
-
- public ConfigurationFormat getFormat(String formatName){
- Objects.requireNonNull(formatName);
- try {
- for (ConfigurationFormat configFormat : ServiceContext.getInstance().getServices(ConfigurationFormat.class)) {
- if(formatName.equals(configFormat.getFormatName())){
- return configFormat;
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- return null;
- }
-
- public Collection<String> getFormatNames(){
- Set<String> result = new HashSet<>();
- try {
- result.addAll(ServiceContext.getInstance().getServices(ConfigurationFormat.class).stream().map(ConfigurationFormat::getFormatName)
- .collect(Collectors.toList()));
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- return result;
- }
-
- public ConfigurationFormat getFormat(Resource resource) {
- Objects.requireNonNull(resource);
- try {
- for (ConfigurationFormat configFormat : ServiceContext.getInstance().getServices(ConfigurationFormat.class)) {
- if(configFormat.isAccepted(resource)){
- return configFormat;
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- return null;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java
new file mode 100644
index 0000000..eb776bc
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.format;
+
+import org.apache.tamaya.core.resource.Resource;
+import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.spi.ConfigurationFormatSpi;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+import org.apache.tamaya.spi.ServiceContext;
+
+/**
+ * Singleton accessor to access registered reader mechanism.
+ */
+public final class DefaultConfigurationFormatSpi implements ConfigurationFormatSpi {
+
+ public ConfigurationFormat getFormat(String formatName){
+ Objects.requireNonNull(formatName);
+ try {
+ for (ConfigurationFormat configFormat : ServiceContext.getInstance().getServices(ConfigurationFormat.class)) {
+ if(formatName.equals(configFormat.getFormatName())){
+ return configFormat;
+ }
+ }
+ } catch (Exception e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public Collection<String> getFormatNames(){
+ Set<String> result = new HashSet<>();
+ try {
+ result.addAll(ServiceContext.getInstance().getServices(ConfigurationFormat.class).stream().map(ConfigurationFormat::getFormatName)
+ .collect(Collectors.toList()));
+ } catch (Exception e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+ public ConfigurationFormat getFormat(Resource resource) {
+ Objects.requireNonNull(resource);
+ try {
+ for (ConfigurationFormat configFormat : ServiceContext.getInstance().getServices(ConfigurationFormat.class)) {
+ if(configFormat.isAccepted(resource)){
+ return configFormat;
+ }
+ }
+ } catch (Exception e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/format/IniFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/format/IniFormat.java b/core/src/main/java/org/apache/tamaya/core/internal/format/IniFormat.java
index 1647d92..ac17d91 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/format/IniFormat.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/format/IniFormat.java
@@ -19,7 +19,7 @@
package org.apache.tamaya.core.internal.format;
import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.spi.ConfigurationFormat;
+import org.apache.tamaya.core.config.ConfigurationFormat;
import org.apache.tamaya.ConfigException;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesFormat.java b/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesFormat.java
index 6646120..d360dae 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesFormat.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesFormat.java
@@ -26,7 +26,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.spi.ConfigurationFormat;
+import org.apache.tamaya.core.config.ConfigurationFormat;
public class PropertiesFormat implements ConfigurationFormat{
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesXmlFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesXmlFormat.java b/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesXmlFormat.java
index b34e78e..7b9b459 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesXmlFormat.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesXmlFormat.java
@@ -19,7 +19,7 @@
package org.apache.tamaya.core.internal.format;
import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.spi.ConfigurationFormat;
+import org.apache.tamaya.core.config.ConfigurationFormat;
import java.io.InputStream;
import java.util.Collections;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java
index 882d68b..ad95021 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java
@@ -40,17 +40,17 @@ public final class ConfigChangeCallbackMethod {
private Method callbackMethod;
public ConfigChangeCallbackMethod(Method callbackMethod) {
- Objects.requireNonNull(callbackMethod);
this.callbackMethod = Optional.of(callbackMethod).filter(
(m) -> void.class.equals(m.getReturnType()) &&
m.getParameterCount() == 1 &&
- m.getParameterTypes()[0].equals(PropertyChangeEvent.class)).get();
+ m.getParameterTypes()[0].equals(ConfigChangeSet.class)).get();
}
public Consumer<ConfigChangeSet> createConsumer(Object instance, Configuration... configurations){
+ // TODO consider also environment !
return event -> {
for(Configuration cfg:configurations){
- if(event.getPropertySource().getMetaInfo().getName().equals(cfg.getMetaInfo().getName())){
+ if(event.getPropertySource().getName().equals(cfg.getName())){
return;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
index 1345625..8a51375 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
@@ -40,9 +40,6 @@ public final class ConfigurationInjector {
* @return the configured type registered.
*/
public static ConfiguredType registerType(Class<?> type){
- if (!ConfiguredType.isConfigured(type)) {
- return null;
- }
return INSTANCE.configuredTypes.computeIfAbsent(type, ConfiguredType::new);
}
@@ -55,9 +52,6 @@ public final class ConfigurationInjector {
*/
public static void configure(Object instance, Configuration... configurations){
Class type = Objects.requireNonNull(instance).getClass();
- if (!ConfiguredType.isConfigured(type)) {
- throw new IllegalArgumentException("Not a configured type: " + type.getName());
- }
ConfiguredType configuredType = registerType(type);
Objects.requireNonNull(configuredType).configure(instance, configurations);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredMethod.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredMethod.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredMethod.java
deleted file mode 100644
index c3dda19..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredMethod.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.inject;
-
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.Objects;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.annotation.ConfiguredProperties;
-import org.apache.tamaya.annotation.ConfiguredProperty;
-import org.apache.tamaya.annotation.DefaultAreas;
-import org.apache.tamaya.core.internal.Utils;
-
-/**
- * Small class that contains and manages all information and access to a configured field and a concrete instance current
- * it (referenced by a weak reference). It also implements all aspects current keys filtering, conversions any applying the
- * final keys by reflection.
- */
-public class ConfiguredMethod {
-
- /**
- * The configured field instance.
- */
- private Method annotatedMethod;
-
- /**
- * Models a configured field and provides mechanisms for injection.
- *
- * @param method the method instance.
- */
- public ConfiguredMethod(Method method) {
- this.annotatedMethod = Objects.requireNonNull(method);
- }
-
-
- /**
- * Evaluate the initial keys fromMap the configuration and applyChanges it to the field.
- *
- * @param target the target instance.
- * @param configurations Configuration instances that replace configuration served by services. This allows
- * more easily testing and adaption.
- * @throws ConfigException if evaluation or conversion failed.
- */
- public void applyInitialValue(Object target, Configuration... configurations) throws ConfigException {
- String configValue = InjectionUtils.getConfigValue(this.annotatedMethod, configurations);
- applyValue(target, configValue, false, configurations);
- }
-
- /**
- * This method reapplies a changed configuration keys to the field.
- *
- * @param target the target instance, not null.
- * @param configValue the new keys to be applied, null will trigger the evaluation current the configured default keys.
- * @param resolve set to true, if expression resolution should be applied on the keys passed.
- * @throws org.apache.tamaya.ConfigException if the configuration required could not be resolved or converted.
- */
- public void applyValue(Object target, String configValue, boolean resolve, Configuration... configurations) throws ConfigException {
- Objects.requireNonNull(target);
- try {
- if (resolve && configValue != null) {
- // net step perform exression resolution, if any
- configValue = Configuration.evaluateValue(configValue, configurations);
- }
- // Check for adapter/filter
- Object value = InjectionUtils.adaptValue(this.annotatedMethod, this.annotatedMethod.getParameterTypes()[0], configValue);
- annotatedMethod.setAccessible(true);
- annotatedMethod.invoke(target, value);
- } catch (Exception e) {
- throw new ConfigException("Failed to annotation configured method: " + this.annotatedMethod.getDeclaringClass()
- .getName() + '.' + annotatedMethod.getName(), e);
- }
- }
-
-
-
- /**
- * This method checks if the given (qualified) configuration key is referenced fromMap this field.
- * This is useful to determine, if a key changed in a configuration should trigger any change events
- * on the related instances.
- *
- * @param key the (qualified) configuration key, not null.
- * @return true, if the key is referenced.
- */
- public boolean matchesKey(String key) {
- DefaultAreas areasAnnot = this.annotatedMethod.getDeclaringClass().getAnnotation(DefaultAreas.class);
- Collection<ConfiguredProperty> configuredProperties =
- Utils.getAnnotations(this.annotatedMethod, ConfiguredProperty.class, ConfiguredProperties.class);
- for(ConfiguredProperty prop: configuredProperties) {
- if (InjectionUtils.evaluateKeys(this.annotatedMethod, areasAnnot, prop).contains(key)) {
- return true;
- }
- }
- return false;
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java
new file mode 100644
index 0000000..3667f5a
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.inject;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.Consumer;
+
+import org.apache.tamaya.ConfigChangeSet;
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.annotation.*;
+import org.apache.tamaya.core.internal.Utils;
+
+/**
+ * Small class that contains and manages all information and access to a configured field and a concrete instance current
+ * it (referenced by a weak reference). It also implements all aspects current keys filtering, conversions any applying the
+ * final keys by reflection.
+ */
+public class ConfiguredSetterMethod {
+
+ /**
+ * The configured field instance.
+ */
+ private Method setterMethod;
+
+ /**
+ * Models a configured field and provides mechanisms for injection.
+ *
+ * @param method the method instance.
+ */
+ public ConfiguredSetterMethod(Method method) {
+ this.setterMethod = Optional.of(method).filter(
+ (m) -> void.class.equals(m.getReturnType()) &&
+ m.getParameterCount() == 1).get();
+ }
+
+ public Consumer<ConfigChangeSet> createConsumer(Object instance, Configuration... configurations){
+ // TODO consider environment as well
+ return event -> {
+ for(Configuration cfg:configurations){
+ if(event.getPropertySource().getName().equals(cfg.getName())){
+ // ignore these changes, since this config is overridden.
+ return;
+ }
+ }
+ String configValue = InjectionUtils.getConfigValue(setterMethod, configurations);
+ applyValue(instance,configValue, false, configurations);
+ };
+ }
+
+
+ /**
+ * Evaluate the initial keys fromMap the configuration and applyChanges it to the field.
+ *
+ * @param target the target instance.
+ * @param configurations Configuration instances that replace configuration served by services. This allows
+ * more easily testing and adaption.
+ * @throws ConfigException if evaluation or conversion failed.
+ */
+ public void applyInitialValue(Object target, Configuration... configurations) throws ConfigException {
+ String configValue = InjectionUtils.getConfigValue(this.setterMethod, configurations);
+ applyValue(target, configValue, false, configurations);
+ }
+
+ /**
+ * This method reapplies a changed configuration keys to the field.
+ *
+ * @param target the target instance, not null.
+ * @param configValue the new keys to be applied, null will trigger the evaluation current the configured default keys.
+ * @param resolve set to true, if expression resolution should be applied on the keys passed.
+ * @throws org.apache.tamaya.ConfigException if the configuration required could not be resolved or converted.
+ */
+ public void applyValue(Object target, String configValue, boolean resolve, Configuration... configurations) throws ConfigException {
+ Objects.requireNonNull(target);
+ try {
+ if (resolve && configValue != null) {
+ // net step perform exression resolution, if any
+ configValue = Configuration.evaluateValue(configValue, configurations);
+ }
+ // Check for adapter/filter
+ Object value = InjectionUtils.adaptValue(this.setterMethod, this.setterMethod.getParameterTypes()[0], configValue);
+ setterMethod.setAccessible(true);
+ setterMethod.invoke(target, value);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to annotation configured method: " + this.setterMethod.getDeclaringClass()
+ .getName() + '.' + setterMethod.getName(), e);
+ }
+ }
+
+
+
+ /**
+ * This method checks if the given (qualified) configuration key is referenced fromMap this field.
+ * This is useful to determine, if a key changed in a configuration should trigger any change events
+ * on the related instances.
+ *
+ * @param key the (qualified) configuration key, not null.
+ * @return true, if the key is referenced.
+ */
+ public boolean matchesKey(String key) {
+ DefaultAreas areasAnnot = this.setterMethod.getDeclaringClass().getAnnotation(DefaultAreas.class);
+ Collection<ConfiguredProperty> configuredProperties =
+ Utils.getAnnotations(this.setterMethod, ConfiguredProperty.class, ConfiguredProperties.class);
+ for(ConfiguredProperty prop: configuredProperties) {
+ if (InjectionUtils.evaluateKeys(this.setterMethod, areasAnnot, prop).contains(key)) {
+ return true;
+ }
+ }
+ if (InjectionUtils.evaluateKeys(this.setterMethod, areasAnnot).contains(key)) {
+ return true;
+ }
+ return false;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
index 491041d..deec910 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
@@ -18,18 +18,15 @@
*/
package org.apache.tamaya.core.internal.inject;
-import java.beans.PropertyChangeEvent;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
+import org.apache.tamaya.ConfigChangeSet;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.PropertySource;
-import org.apache.tamaya.annotation.ConfiguredProperties;
-import org.apache.tamaya.annotation.ConfiguredProperty;
-import org.apache.tamaya.annotation.DefaultAreas;
-import org.apache.tamaya.annotation.ObservesConfigChange;
+import org.apache.tamaya.annotation.*;
import org.apache.tamaya.core.internal.Utils;
/**
@@ -38,87 +35,120 @@ import org.apache.tamaya.core.internal.Utils;
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public class ConfiguredType {
- /** A list with all annotated instance variables. */
+ /**
+ * A list with all annotated instance variables.
+ */
private List<ConfiguredField> configuredFields = new ArrayList<>();
- /** A list with all annotated methods (templates). */
- private List<ConfiguredMethod> configuredMethods = new ArrayList<>();
- /** A list with all callback methods listening to config changes. */
+ /**
+ * A list with all annotated methods (templates).
+ */
+ private List<ConfiguredSetterMethod> configuredSetterMethods = new ArrayList<>();
+ /**
+ * A list with all callback methods listening to config changes.
+ */
private List<ConfigChangeCallbackMethod> callbackMethods = new ArrayList<>();
- /** The basic type. */
- private Class type;
+ /**
+ * The basic type.
+ */
+ private Class type;
/**
* Creates an instance of this class hereby evaluating the config annotations given for later effective
* injection (configuration) of instances.
+ *
* @param type the instance type.
*/
- public ConfiguredType(Class type) {
+ public ConfiguredType(Class type) {
this.type = Objects.requireNonNull(type);
initFields(type);
initMethods(type);
}
+ private void initFields(Class type) {
+ for (Field f : type.getDeclaredFields()) {
+ if (f.isAnnotationPresent(NoConfig.class)) {
+ continue;
+ }
+ try {
+ ConfiguredField configuredField = new ConfiguredField(f);
+ configuredFields.add(configuredField);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to initialized configured field: " +
+ f.getDeclaringClass().getName() + '.' + f.getName(), e);
+ }
+ }
+ }
+
private void initMethods(Class type) {
+ // TODO revisit this logic here...
for (Method m : type.getDeclaredMethods()) {
+ if (m.isAnnotationPresent(NoConfig.class)) {
+ continue;
+ }
ObservesConfigChange mAnnot = m.getAnnotation(ObservesConfigChange.class);
- if (mAnnot != null) {
- if (m.getParameterTypes().length != 1) {
- continue;
- }
- if (!m.getParameterTypes()[0].equals(PropertyChangeEvent.class)) {
- continue;
- }
- if (!void.class.equals(m.getReturnType())) {
- continue;
- }
- try {
- this.callbackMethods.add(new ConfigChangeCallbackMethod(m));
- } catch (Exception e) {
- throw new ConfigException("Failed to initialized configured callback method: " +
- m.getDeclaringClass().getName() + '.' + m.getName(), e);
+ Collection<ConfiguredProperty> propertiesAnnots = Utils.getAnnotations(m, ConfiguredProperty.class, ConfiguredProperties.class);
+ if (type.isInterface()) {
+ // it is a template
+ if (mAnnot != null) {
+ if (m.isDefault()) {
+ addObserverMethod(m);
+ }
+ } else {
+ if (m.isDefault()) {
+ addPropertySetter(m, propertiesAnnots);
+ }
}
} else {
- Collection<ConfiguredProperty> propertiesAnnots = Utils.getAnnotations(m, ConfiguredProperty.class, ConfiguredProperties.class);
- if (!propertiesAnnots.isEmpty()) {
- try {
- ConfiguredMethod configuredMethod = new ConfiguredMethod(m);
- configuredMethods.add(configuredMethod);
- } catch (Exception e) {
- throw new ConfigException("Failed to initialized configured method: " +
- m.getDeclaringClass().getName() + '.' + m.getName(), e);
- }
+ if (mAnnot != null) {
+ addObserverMethod(m);
+ } else {
+ addPropertySetter(m, propertiesAnnots);
}
}
}
}
- private void initFields(Class type) {
- for (Field f : type.getDeclaredFields()) {
- ConfiguredProperties propertiesAnnot = f.getAnnotation(ConfiguredProperties.class);
- if (propertiesAnnot != null) {
- try {
- ConfiguredField configuredField = new ConfiguredField(f);
- configuredFields.add(configuredField);
- } catch (Exception e) {
- throw new ConfigException("Failed to initialized configured field: " +
- f.getDeclaringClass().getName() + '.' + f.getName(), e);
- }
- } else {
- ConfiguredProperty propertyAnnot = f.getAnnotation(ConfiguredProperty.class);
- if (propertyAnnot != null) {
+ private boolean addPropertySetter(Method m, Collection<ConfiguredProperty> propertiesAnnots) {
+ if (!propertiesAnnots.isEmpty()) {
+ if (m.getParameterTypes().length == 0) {
+ // getter method
+ Class<?> returnType = m.getReturnType();
+ if (!void.class.equals(returnType)) {
try {
- ConfiguredField configuredField = new ConfiguredField(f);
- configuredFields.add(configuredField);
+ configuredSetterMethods.add(new ConfiguredSetterMethod(m));
+ return true;
} catch (Exception e) {
- throw new ConfigException("Failed to initialized configured field: " +
- f.getDeclaringClass().getName() + '.' + f.getName(), e);
+ throw new ConfigException("Failed to initialized configured setter method: " +
+ m.getDeclaringClass().getName() + '.' + m.getName(), e);
}
}
}
}
+ return false;
+ }
+
+
+
+ private void addObserverMethod(Method m) {
+ if (m.getParameterTypes().length != 1) {
+ return;
+ }
+ if (!m.getParameterTypes()[0].equals(ConfigChangeSet.class)) {
+ return;
+ }
+ if (!void.class.equals(m.getReturnType())) {
+ return;
+ }
+ try {
+ this.callbackMethods.add(new ConfigChangeCallbackMethod(m));
+ } catch (Exception e) {
+ throw new ConfigException("Failed to initialized configured callback method: " +
+ m.getDeclaringClass().getName() + '.' + m.getName(), e);
+ }
}
+
/**
* Method called to configure an instance.
*
@@ -129,23 +159,23 @@ public class ConfiguredType {
public void configure(Object instance, Configuration... configurations) {
for (ConfiguredField field : configuredFields) {
field.applyInitialValue(instance, configurations);
- // TODO, if reinjection on changes should be done, corresponding callbacks could be registered here
}
- for (ConfiguredMethod method : configuredMethods) {
+ for (ConfiguredSetterMethod method : configuredSetterMethods) {
method.applyInitialValue(instance, configurations);
// TODO, if method should be recalled on changes, corresponding callbacks could be registered here
+ WeakConfigListenerManager.of().registerConsumer(instance, method.createConsumer(instance, configurations));
}
// Register callbacks for this intance (weakly)
- for(ConfigChangeCallbackMethod callback: callbackMethods){
+ for (ConfigChangeCallbackMethod callback : callbackMethods) {
WeakConfigListenerManager.of().registerConsumer(instance, callback.createConsumer(instance, configurations));
}
}
- private String getName(Object source){
- if(source instanceof PropertySource){
- PropertySource ps = (PropertySource)source;
- return ps.getMetaInfo().getName();
+ private String getName(Object source) {
+ if (source instanceof PropertySource) {
+ PropertySource ps = (PropertySource) source;
+ return ps.getName();
}
return "N/A";
}
@@ -156,7 +186,7 @@ public class ConfiguredType {
return true;
}
- public static boolean isConfigured(Class type) {
+ public static boolean isConfigured(Class type) {
if (type.getAnnotation(DefaultAreas.class) != null) {
return true;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/inject/InjectionUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/InjectionUtils.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/InjectionUtils.java
index e632ff9..e8fe9b8 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/InjectionUtils.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/InjectionUtils.java
@@ -1,5 +1,6 @@
package org.apache.tamaya.core.internal.inject;
+import java.beans.PropertyChangeEvent;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
@@ -11,6 +12,7 @@ import java.util.List;
import java.util.ListIterator;
import org.apache.tamaya.Codec;
+import org.apache.tamaya.ConfigChangeSet;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.annotation.ConfiguredProperties;
@@ -75,6 +77,37 @@ final class InjectionUtils {
}
/**
+ * Evaluates all absolute configuration key based on the member name found.
+ *
+ * @param areasAnnot the (optional) annotation definining areas to be looked up.
+ * @return the list current keys in order how they should be processed/looked up.
+ */
+ public static List<String> evaluateKeys(Member member, DefaultAreas areasAnnot) {
+ List<String> keys = new ArrayList<>();
+ String name = member.getName();
+ String mainKey;
+ if(name.startsWith("get") || name.startsWith("set")){
+ mainKey = Character.toLowerCase(name.charAt(3)) + name.substring(4);
+ }
+ else{
+ mainKey = Character.toLowerCase(name.charAt(0)) + name.substring(1);
+ }
+ keys.add(mainKey);
+ if (areasAnnot != null) {
+ // Add prefixed entries, including absolute (root) entry for "" area keys.
+ for (String area : areasAnnot.value()) {
+ if(!area.isEmpty()) {
+ keys.add(area + '.' + mainKey);
+ }
+ }
+ }
+ else{ // add package name
+ keys.add(member.getDeclaringClass().getName()+'.'+mainKey);
+ }
+ return keys;
+ }
+
+ /**
* Internally evaluated the current valid configuration keys based on the given annotations present.
*
* @return the keys to be returned, or null.
@@ -85,6 +118,7 @@ final class InjectionUtils {
return getConfigValueInternal(method, areasAnnot, loadPolicy, configurations);
}
+
/**
* Internally evaluated the current valid configuration keys based on the given annotations present.
*
@@ -106,30 +140,40 @@ final class InjectionUtils {
element, ConfiguredProperty.class, ConfiguredProperties.class);
DefaultValue defaultAnnot = element.getAnnotation(DefaultValue.class);
String configValue = null;
- for(ConfiguredProperty prop: configuredProperties){
- List<String> keys = InjectionUtils.evaluateKeys((Member)element, areasAnnot, prop);
- Configuration config = InjectionUtils.getConfiguration(prop, configurations);
- for (String key : keys) {
- if (config.containsKey(key)) {
- configValue = config.get(key).orElse(null);
- }
- if (configValue != null) {
- break;
- }
- }
- if (configValue != null) {
- // net step perform expression resolution, if any
- return Configuration.evaluateValue(configValue, config);
+ if(configuredProperties.isEmpty()){
+ List<String> keys = InjectionUtils.evaluateKeys((Member)element, areasAnnot);
+ Configuration config = InjectionUtils.getConfiguration("default", configurations);
+ configValue = evaluteConfigValue(configValue, keys, config);
+ }
+ else {
+ for (ConfiguredProperty prop : configuredProperties) {
+ List<String> keys = InjectionUtils.evaluateKeys((Member) element, areasAnnot, prop);
+ Configuration config = InjectionUtils.getConfiguration(prop, configurations);
+ configValue = evaluteConfigValue(configValue, keys, config);
}
}
if (configValue == null && defaultAnnot != null) {
return defaultAnnot.value();
}
- return null;
+ return configValue;
+ }
+
+ private static String evaluteConfigValue(String configValue, List<String> keys, Configuration config) {
+ for (String key : keys) {
+ configValue = config.get(key).orElse(null);
+ if (configValue != null) {
+ break;
+ }
+ }
+ if (configValue != null) {
+ // net step perform expression resolution, if any
+ configValue = Configuration.evaluateValue(configValue, config);
+ }
+ return configValue;
}
- @SuppressWarnings("rawtypes")
+ @SuppressWarnings("rawtypes")
public static <T> T adaptValue(AnnotatedElement element, Class<T> targetType, String configValue){
try {
// Check for adapter/filter
@@ -164,7 +208,7 @@ final class InjectionUtils {
public static Configuration getConfiguration(String name, Configuration... configurations) {
if(name!=null) {
for(Configuration conf: configurations){
- if(name.equals(conf.getMetaInfo().getName())){
+ if(name.equals(conf.getName())){
return conf;
}
}
@@ -172,7 +216,7 @@ final class InjectionUtils {
}
else{
for(Configuration conf: configurations){
- if("default".equals(conf.getMetaInfo().getName())){
+ if("default".equals(conf.getName())){
return conf;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/properties/DefaultCodecsSingletonSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/properties/DefaultCodecsSingletonSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/properties/DefaultCodecsSingletonSpi.java
deleted file mode 100644
index 2b64bea..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/properties/DefaultCodecsSingletonSpi.java
+++ /dev/null
@@ -1,170 +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.core.internal.properties;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.ZoneId;
-import java.util.Currency;
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Function;
-
-import org.apache.tamaya.Codec;
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.annotation.WithCodec;
-import org.apache.tamaya.spi.CodecsSingletonSpi;
-
-/**
- * Default codecs singleton, which provides default codesc for all kind of classes out of the box, which will be
- * instantiatable from configuration, if one of the following is given:
- * <ul>
- * <li>static factory methods using a String as simgle argument, called {@code of, valueOf, getInstance, instance, parse}</li>
- * <li>have constructors taking a single String</li>
- * </ul>
- */
-@SuppressWarnings({"rawtypes", "unchecked"})
-public class DefaultCodecsSingletonSpi implements CodecsSingletonSpi {
-
-
- private Map<Class,Codec> adapters = new ConcurrentHashMap<>();
-
- public DefaultCodecsSingletonSpi(){
- // Add default adapters
- register(char.class, (s) -> s.charAt(0), (ch) -> String.valueOf(ch));
- register(byte.class, Byte::parseByte, Object::toString);
- register(short.class, Short::parseShort, Object::toString);
- register(int.class, Integer::parseInt, Object::toString);
- register(long.class, Long::parseLong, Object::toString);
- register(boolean.class, Boolean::parseBoolean, b -> String.valueOf(b));
- register(float.class, Float::parseFloat, f -> String.valueOf(f));
- register(double.class, Double::parseDouble, d -> String.valueOf(d));
-
- register(Character.class, (s) -> s.charAt(0), Object::toString);
- register(Byte.class, Byte::valueOf, Object::toString);
- register(Short.class, Short::valueOf, String::valueOf);
- register(Integer.class, Integer::valueOf, Object::toString);
- register(Long.class, Long::valueOf, Object::toString);
- register(Boolean.class, Boolean::valueOf, b -> String.valueOf(b));
- register(Float.class, Float::valueOf, f -> String.valueOf(f));
- register(Double.class, Double::valueOf, d -> String.valueOf(d));
- register(BigDecimal.class, BigDecimal::new, String::valueOf);
- register(BigInteger.class, BigInteger::new, String::valueOf);
-
- register(Currency.class, Currency::getInstance, Object::toString);
-
- register(LocalDate.class, LocalDate::parse, Object::toString);
- register(LocalTime.class, LocalTime::parse, Object::toString);
- register(LocalDateTime.class, LocalDateTime::parse, Object::toString);
- register(ZoneId.class, ZoneId::of, ZoneId::getId);
- }
-
- @Override
- public <T> Codec<T> register(Class<T> targetType, Codec<T> adapter){
- return adapters.put(targetType, adapter);
- }
-
- @Override
- public <T> Codec<T> getCodec(Class<T> targetType, WithCodec adapterAnnot){
- Codec codec = null;
- Class<? extends Codec> configuredCodec = null;
- if(adapterAnnot != null){
- configuredCodec = adapterAnnot.value();
- if(!configuredCodec.equals(Codec.class)){
- try{
- codec = configuredCodec.newInstance();
- }
- catch(Exception e){
- throw new ConfigException("Invalid codec configured.", e);
- }
- }
- }
- if(codec == null){
- codec = adapters.get(targetType);
- }
- if(codec == null){
- codec = getDefaultCodec(targetType);
- }
- if(codec == null){
- throw new ConfigException("No Codec found for " + targetType.getName());
- }
- return codec;
- }
-
- private <T> Codec getDefaultCodec(Class<T> targetType) {
- Function<String, T> decoder = null;
- Method factoryMethod = getFactoryMethod(targetType, "of", "valueOf", "instanceOf", "getInstance", "from", "parse");
- if(factoryMethod!=null){
- decoder = (s) -> {
- try{
- factoryMethod.setAccessible(true);
- return targetType.cast(factoryMethod.invoke(s));
- }
- catch (Exception e){
- throw new ConfigException("Failed to decode '"+s+"'", e);
- }
- };
- }
- if(decoder==null) {
- try {
- Constructor<T> constr = targetType.getDeclaredConstructor(String.class);
- decoder = (s) -> {
- try{
- constr.setAccessible(true);
- return constr.newInstance(s);
- }
- catch (Exception e){
- throw new ConfigException("Failed to decode '"+s+"'", e);
- }
- };
- } catch (Exception e) {
- // ignore, TODO log finest
- }
- }
- if(decoder!=null) {
- return register(targetType, decoder, String::valueOf);
- }
- return null;
- }
-
- private Method getFactoryMethod(Class<?> type, String... methodNames) {
- Method m;
- for(String name:methodNames){
- try{
- m = type.getDeclaredMethod(name, String.class);
- return m;
- }
- catch(Exception e){
- // ignore, TODO log finest
- }
- }
- return null;
- }
-
- @Override
- public boolean isTargetTypeSupported(Class<?> targetType){
- return adapters.containsKey(targetType);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/resources/DefaultPathResourceLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resources/DefaultPathResourceLoader.java b/core/src/main/java/org/apache/tamaya/core/internal/resources/DefaultPathResourceLoader.java
deleted file mode 100644
index 50c0402..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/resources/DefaultPathResourceLoader.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.core.internal.resources;
-
-import org.apache.tamaya.core.spi.PathResolver;
-import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.resource.ResourceLoader;
-
-import org.apache.tamaya.spi.ServiceContext;
-
-import java.util.*;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.stream.Collectors;
-
-/**
- * Singleton accessor to access registered reader mechanism.
- */
-public class DefaultPathResourceLoader implements ResourceLoader{
-
- private static final Logger LOG = Logger.getLogger(DefaultPathResourceLoader.class.getName());
-
- @Override
- public Collection<String> getResolverIds(){
- return ServiceContext.getInstance().getServices(PathResolver.class).stream().map(PathResolver::getResolverId)
- .collect(Collectors.toSet());
- }
-
- @Override
- public List<Resource> getResources(String... expressions){
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if(cl==null){
- cl = getClass().getClassLoader();
- }
- return getResources(cl, Arrays.asList(expressions));
- }
-
- @Override
- public List<Resource> getResources(Collection<String> expressions){
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if(cl==null){
- cl = getClass().getClassLoader();
- }
- return getResources(cl, expressions);
- }
-
- @Override
- public List<Resource> getResources(ClassLoader classLoader, String... expressions) {
- return getResources(classLoader, Arrays.asList(expressions));
- }
-
- @Override
- public List<Resource> getResources(ClassLoader classLoader, Collection<String> expressions){
- List<Resource> resources = new ArrayList<>();
- for(PathResolver resolver : ServiceContext.getInstance().getServices(PathResolver.class)){
- try{
- resources.addAll(resolver.resolve(classLoader, expressions));
- }
- catch(Exception e){
- LOG.log(Level.FINEST, e, () -> "Resource not found: " + expressions.toString());
- }
- }
- return resources;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/resources/DefaultResourceLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resources/DefaultResourceLoader.java b/core/src/main/java/org/apache/tamaya/core/internal/resources/DefaultResourceLoader.java
new file mode 100644
index 0000000..9f2a8cb
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resources/DefaultResourceLoader.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.resources;
+
+import org.apache.tamaya.core.spi.PathResolver;
+import org.apache.tamaya.core.resource.Resource;
+import org.apache.tamaya.core.resource.ResourceLoader;
+
+import org.apache.tamaya.spi.ServiceContext;
+
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.stream.Collectors;
+
+/**
+ * Singleton accessor to access registered reader mechanism.
+ */
+public class DefaultResourceLoader implements ResourceLoader{
+
+ private static final Logger LOG = Logger.getLogger(DefaultResourceLoader.class.getName());
+
+ @Override
+ public Collection<String> getResolverIds(){
+ return ServiceContext.getInstance().getServices(PathResolver.class).stream().map(PathResolver::getResolverId)
+ .collect(Collectors.toSet());
+ }
+
+ @Override
+ public List<Resource> getResources(String... expressions){
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if(cl==null){
+ cl = getClass().getClassLoader();
+ }
+ return getResources(cl, Arrays.asList(expressions));
+ }
+
+ @Override
+ public List<Resource> getResources(Collection<String> expressions){
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if(cl==null){
+ cl = getClass().getClassLoader();
+ }
+ return getResources(cl, expressions);
+ }
+
+ @Override
+ public List<Resource> getResources(ClassLoader classLoader, String... expressions) {
+ return getResources(classLoader, Arrays.asList(expressions));
+ }
+
+ @Override
+ public List<Resource> getResources(ClassLoader classLoader, Collection<String> expressions){
+ List<Resource> resources = new ArrayList<>();
+ for(PathResolver resolver : ServiceContext.getInstance().getServices(PathResolver.class)){
+ try{
+ resources.addAll(resolver.resolve(classLoader, expressions));
+ }
+ catch(Exception e){
+ LOG.log(Level.FINEST, e, () -> "Resource not found: " + expressions.toString());
+ }
+ }
+ return resources;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/AbstractClasspathAwarePropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/AbstractClasspathAwarePropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/AbstractClasspathAwarePropertySource.java
index ab8c2ab..58fb301 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/AbstractClasspathAwarePropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/AbstractClasspathAwarePropertySource.java
@@ -37,8 +37,8 @@ public abstract class AbstractClasspathAwarePropertySource extends AbstractPrope
public AbstractClasspathAwarePropertySource(ClassLoader classLoader, AbstractClasspathAwarePropertySource parentConfig,
Set<String> sourceExpressions, long configReadDT, Map<String, String> entries,
- MetaInfo metaInfo, Set<String> sources, List<Throwable> errors){
- super(metaInfo);
+ String name, Set<String> sources, List<Throwable> errors){
+ super(name);
Objects.requireNonNull(sources, "sources required.");
Objects.requireNonNull(classLoader, "classLoader required.");
this.sources = sources;
@@ -48,8 +48,7 @@ public abstract class AbstractClasspathAwarePropertySource extends AbstractPrope
public AbstractClasspathAwarePropertySource(ClassLoader classLoader, AbstractClasspathAwarePropertySource parentConfig,
String sourceExpression){
- super(MetaInfoBuilder.of().setSourceExpressions(sourceExpression).set("parentConfig", parentConfig.toString())
- .build());
+ super(parentConfig.getName());
Objects.requireNonNull(sources, "sources required.");
Objects.requireNonNull(sourceExpression, "sourceExpression required.");
List<Resource> resources = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(classLoader, sourceExpression);
@@ -63,7 +62,7 @@ public abstract class AbstractClasspathAwarePropertySource extends AbstractPrope
protected abstract void readSource(Map<String,String> targetMap, String source);
@Override
- public Map<String,String> toMap(){
+ public Map<String,String> getProperties(){
Map<String,String> result = new HashMap<>();
for(String source : sources){
// if(!isSourceRead(source)){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java
index 8321afa..6fe3df0 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java
@@ -19,14 +19,7 @@
package org.apache.tamaya.core.properties;
import java.io.Serializable;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
+import java.util.*;
import org.apache.tamaya.MetaInfo;
import org.apache.tamaya.PropertySource;
@@ -40,7 +33,7 @@ public abstract class AbstractPropertySource implements PropertySource, Serializ
*/
private static final long serialVersionUID = -6553955893879292837L;
- protected MetaInfo metaInfo;
+ protected String name;
/**
* The underlying sources.
@@ -50,14 +43,13 @@ public abstract class AbstractPropertySource implements PropertySource, Serializ
/**
* Constructor.
*/
- protected AbstractPropertySource(MetaInfo metaInfo){
- Objects.requireNonNull(metaInfo);
- this.metaInfo = metaInfo;
+ protected AbstractPropertySource(String name){
+ this.name = Objects.requireNonNull(name);
}
@Override
- public MetaInfo getMetaInfo(){
- return metaInfo;
+ public String getName(){
+ return name;
}
@@ -79,30 +71,20 @@ public abstract class AbstractPropertySource implements PropertySource, Serializ
}
@Override
- public boolean containsKey(String key){
- return toMap().containsKey(key);
- }
-
- @Override
public Optional<String> get(String key){
- return Optional.ofNullable(toMap().get(key));
- }
-
- @Override
- public Set<String> keySet(){
- return toMap().keySet();
+ return Optional.ofNullable(getProperties().get(key));
}
@Override
public String toString(){
StringBuilder b = new StringBuilder(getClass().getSimpleName()).append("{\n");
- b.append(" ").append("(").append(MetaInfo.NAME).append(" = ").append(getMetaInfo().getName()).append(")\n");
+ b.append(" ").append("(").append(MetaInfo.NAME).append(" = ").append(getName()).append(")\n");
printContents(b);
return b.append('}').toString();
}
protected String printContents(StringBuilder b){
- Map<String,String> sortMap = toMap();
+ Map<String,String> sortMap = getProperties();
if(!(sortMap instanceof SortedMap)){
sortMap = new TreeMap<>(sortMap);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
index cb6928b..bb95ee5 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
@@ -49,10 +49,9 @@ class AggregatedPropertySource extends AbstractPropertySource {
* @param propertyMaps
* The property sets to be included.
*/
- public AggregatedPropertySource(MetaInfo metaInfo, PropertySource mutableProvider, AggregationPolicy policy, List<PropertySource> propertyMaps) {
- super(MetaInfoBuilder.of(metaInfo).setType("aggregated").build());
- Objects.requireNonNull(policy);
- this.policy = policy;
+ public AggregatedPropertySource(String name, PropertySource mutableProvider, AggregationPolicy policy, List<PropertySource> propertyMaps) {
+ super(name);
+ this.policy = Objects.requireNonNull(policy);
units.addAll(propertyMaps);
this.mutableProvider = mutableProvider;
}
@@ -93,10 +92,10 @@ class AggregatedPropertySource extends AbstractPropertySource {
}
@Override
- public Map<String,String> toMap() {
+ public Map<String,String> getProperties() {
Map<String, String> value = new HashMap<>();
for (PropertySource unit : units) {
- for (Map.Entry<String, String> entry : unit.toMap()
+ for (Map.Entry<String, String> entry : unit.getProperties()
.entrySet()) {
String valueToAdd = this.policy.aggregate(entry.getKey(), value.get(entry.getKey()), entry.getValue());
if(valueToAdd==null){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/BuildablePropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/BuildablePropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/BuildablePropertySource.java
index dd7011e..33eb2a6 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/BuildablePropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/BuildablePropertySource.java
@@ -23,6 +23,7 @@ import org.apache.tamaya.PropertySource;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
+import java.util.UUID;
/**
* Created by Anatole on 07.12.2014.
@@ -30,11 +31,11 @@ import java.util.Optional;
class BuildablePropertySource implements PropertySource
{
- private MetaInfo metaInfo;
+ private String name;
private PropertySource baseProvider;
- public BuildablePropertySource(MetaInfo metaInfo, PropertySource baseProvider) {
- this.metaInfo = Objects.requireNonNull(metaInfo);
+ public BuildablePropertySource(String name, PropertySource baseProvider) {
+ this.name = Objects.requireNonNull(name);
this.baseProvider = Objects.requireNonNull(baseProvider);
}
@@ -44,23 +45,18 @@ class BuildablePropertySource implements PropertySource
}
@Override
- public boolean containsKey(String key) {
- return this.baseProvider.containsKey(key);
+ public Map<String, String> getProperties() {
+ return this.baseProvider.getProperties();
}
@Override
- public Map<String, String> toMap() {
- return this.baseProvider.toMap();
- }
-
- @Override
- public MetaInfo getMetaInfo() {
- return this.metaInfo;
+ public String getName() {
+ return this.name;
}
@Override
public String toString(){
- return "BuildablePropertyProvider -> " + getMetaInfo().toString();
+ return "BuildablePropertyProvider -> " + getName();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
index fc2492d..9510c95 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
@@ -20,10 +20,7 @@ package org.apache.tamaya.core.properties;
import org.apache.tamaya.*;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
@@ -36,7 +33,8 @@ class ContextualPropertySource implements PropertySource {
private Supplier<PropertySource> mapSupplier;
private Supplier<String> isolationKeySupplier;
- private MetaInfo metaInfo;
+ private String name;
+
/**
* Creates a new contextual PropertyMap. Contextual maps delegate to different instances current PropertyMap depending
@@ -45,15 +43,8 @@ class ContextualPropertySource implements PropertySource {
* @param mapSupplier
* @param isolationKeySupplier
*/
- public ContextualPropertySource(MetaInfo metaInfo, Supplier<PropertySource> mapSupplier, Supplier<String> isolationKeySupplier){
- if(metaInfo==null){
- this.metaInfo = MetaInfoBuilder.of().setType("contextual").set("mapSupplier", mapSupplier.toString())
- .set("isolationKeySupplier", isolationKeySupplier.toString()).build();
- }
- else{
- this.metaInfo = MetaInfoBuilder.of(metaInfo).setType("contextual").set("mapSupplier", mapSupplier.toString())
- .set("isolationKeySupplier", isolationKeySupplier.toString()).build();
- }
+ public ContextualPropertySource(String name, Supplier<PropertySource> mapSupplier, Supplier<String> isolationKeySupplier){
+ this.name = Optional.ofNullable(name).orElse("<noname>");
Objects.requireNonNull(mapSupplier);
Objects.requireNonNull(isolationKeySupplier);
this.mapSupplier = mapSupplier;
@@ -94,18 +85,13 @@ class ContextualPropertySource implements PropertySource {
}
@Override
- public boolean containsKey(String key){
- return getContextualMap().containsKey(key);
+ public Map<String,String> getProperties(){
+ return getContextualMap().getProperties();
}
@Override
- public Map<String,String> toMap(){
- return getContextualMap().toMap();
- }
-
- @Override
- public MetaInfo getMetaInfo(){
- return this.metaInfo;
+ public String getName(){
+ return this.name;
}
@Override
@@ -113,11 +99,6 @@ class ContextualPropertySource implements PropertySource {
return getContextualMap().get(key);
}
- @Override
- public Set<String> keySet(){
- return getContextualMap().keySet();
- }
-
/**
* Apply a config change to this item. Hereby the change must be related to the same instance.
* @param change the config change
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
index 611ed0d..3c08de7 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
@@ -40,7 +40,8 @@ class DelegatingPropertySource implements PropertySource {
private PropertySource mainMap;
private Map<String,String> parentMap;
- private MetaInfo metaInfo;
+ private String name;
+
/**
* Creates a mew instance, with aggregation polilcy
@@ -49,17 +50,8 @@ class DelegatingPropertySource implements PropertySource {
* @param mainMap The main ConfigMap.
* @param parentMap The delegated parent ConfigMap.
*/
- public DelegatingPropertySource(MetaInfo metaInfo, PropertySource mainMap, Map<String, String> parentMap){
- if(metaInfo==null) {
- this.metaInfo =
- MetaInfoBuilder.of().setType("delegate").set("provider", mainMap.toString()).set("delegate", parentMap.toString())
- .build();
- }
- else{
- this.metaInfo =
- MetaInfoBuilder.of(metaInfo).setType("delegate").set("provider", mainMap.toString()).set("delegate", parentMap.toString())
- .build();
- }
+ public DelegatingPropertySource(String name, PropertySource mainMap, Map<String, String> parentMap){
+ this.name = Optional.of(name).orElse("<noname>");
this.parentMap = Objects.requireNonNull(parentMap);
this.parentMap = Objects.requireNonNull(parentMap);
}
@@ -70,18 +62,13 @@ class DelegatingPropertySource implements PropertySource {
}
@Override
- public boolean containsKey(String key){
- return keySet().contains(key);
- }
-
- @Override
- public Map<String,String> toMap(){
+ public Map<String,String> getProperties(){
return null;
}
@Override
- public MetaInfo getMetaInfo(){
- return this.metaInfo;
+ public String getName(){
+ return this.name;
}
@Override
@@ -94,13 +81,6 @@ class DelegatingPropertySource implements PropertySource {
}
@Override
- public Set<String> keySet(){
- Set<String> keys = new HashSet<>(mainMap.keySet());
- keys.addAll(parentMap.keySet());
- return keys;
- }
-
- @Override
public String toString(){
return super.toString() + "(mainMap=" + mainMap + ", delegate=" + parentMap + ")";
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/EnvironmentPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/EnvironmentPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/EnvironmentPropertySource.java
index 365b107..9958f8d 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/EnvironmentPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/EnvironmentPropertySource.java
@@ -27,12 +27,12 @@ class EnvironmentPropertySource extends AbstractPropertySource {
private static final long serialVersionUID = 4753258482658331010L;
- public Map<String,String> toMap(){
+ public Map<String,String> getProperties(){
return System.getenv();
}
public EnvironmentPropertySource(){
- super(MetaInfoBuilder.of().setType("env-properties").build());
+ super("<System.getenv()>");
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
index 3558046..b829769 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
@@ -34,18 +34,16 @@ class FilteredPropertySource extends AbstractPropertySource {
private PropertySource unit;
private Predicate<String> filter;
- public FilteredPropertySource(MetaInfo metaInfo, PropertySource configuration, Predicate<String> filter){
- super(metaInfo==null?MetaInfoBuilder.of(configuration.getMetaInfo()).setType("filtered").set("filter", filter.toString()).build():
- MetaInfoBuilder.of(metaInfo).setType("filtered").set("filter", filter.toString()).build());
- Objects.requireNonNull(configuration);
+ public FilteredPropertySource(String name, PropertySource configuration, Predicate<String> filter){
+ super(name==null?Objects.requireNonNull(configuration).getName():name);
this.unit = configuration;
this.filter = filter;
}
@Override
- public Map<String,String> toMap(){
+ public Map<String,String> getProperties(){
final Map<String,String> result = new HashMap<>();
- this.unit.toMap().entrySet().forEach(e -> {
+ this.unit.getProperties().entrySet().forEach(e -> {
if(filter.test(e.getKey())){
result.put(e.getKey(), e.getValue());
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/properties/FreezedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/FreezedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/FreezedPropertySource.java
index 204c1c9..333211d 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/FreezedPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/FreezedPropertySource.java
@@ -20,11 +20,7 @@ package org.apache.tamaya.core.properties;
import java.io.Serializable;
import java.time.Instant;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
+import java.util.*;
import org.apache.tamaya.ConfigChangeSet;
import org.apache.tamaya.MetaInfo;
@@ -39,26 +35,21 @@ final class FreezedPropertySource implements PropertySource, Serializable{
private static final long serialVersionUID = 3365413090311267088L;
// private Map<String,Map<String,String>> fieldMMetaInfo = new HashMap<>();
- private MetaInfo metaInfo;
+ private String name;
private Map<String,String> properties = new HashMap<>();
- private FreezedPropertySource(MetaInfo metaInfo, PropertySource propertyMap) {
- Map<String, String> map = propertyMap.toMap();
+ private FreezedPropertySource(String name, PropertySource propertyMap) {
+ Map<String, String> map = propertyMap.getProperties();
this.properties.putAll(map);
this.properties = Collections.unmodifiableMap(this.properties);
- if (metaInfo == null) {
- this.metaInfo =
- MetaInfoBuilder.of(propertyMap.getMetaInfo()).set("freezedAt", Instant.now().toString()).build();
- } else {
- this.metaInfo = metaInfo;
- }
+ this.name = Optional.ofNullable(name).orElse(propertyMap.getName()+"(freezed)");
}
- public static PropertySource of(MetaInfo metaInfo, PropertySource propertyProvider){
+ public static PropertySource of(String name, PropertySource propertyProvider){
if(propertyProvider instanceof FreezedPropertySource){
return propertyProvider;
}
- return new FreezedPropertySource(metaInfo, propertyProvider);
+ return new FreezedPropertySource(name, propertyProvider);
}
@Override
@@ -75,18 +66,13 @@ final class FreezedPropertySource implements PropertySource, Serializable{
}
@Override
- public boolean containsKey(String key){
- return properties.containsKey(key);
- }
-
- @Override
- public Map<String,String> toMap(){
+ public Map<String,String> getProperties(){
return Collections.unmodifiableMap(this.properties);
}
@Override
- public MetaInfo getMetaInfo(){
- return this.metaInfo;
+ public String getName(){
+ return this.name;
}
@Override
@@ -94,9 +80,5 @@ final class FreezedPropertySource implements PropertySource, Serializable{
return Optional.ofNullable(properties.get(key));
}
- @Override
- public Set<String> keySet(){
- return properties.keySet();
- }
}