tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [1/2] incubator-tamaya git commit: Added ConfiguratoinFOrmats singleton to formats module. Moved commons-config related aspects into separate integration module.
Date Fri, 13 Feb 2015 23:49:16 GMT
Repository: incubator-tamaya
Updated Branches:
  refs/heads/master c15fb1c64 -> bd9970692


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bd997069/modules/integration/commons/src/main/java/org/apache/tamaya/integration/commons/IniConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/modules/integration/commons/src/main/java/org/apache/tamaya/integration/commons/IniConfigurationFormat.java
b/modules/integration/commons/src/main/java/org/apache/tamaya/integration/commons/IniConfigurationFormat.java
new file mode 100644
index 0000000..2f80977
--- /dev/null
+++ b/modules/integration/commons/src/main/java/org/apache/tamaya/integration/commons/IniConfigurationFormat.java
@@ -0,0 +1,60 @@
+/*
+ * 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.commons;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalINIConfiguration;
+import org.apache.commons.configuration.SubnodeConfiguration;
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.ConfigurationDataBuilder;
+import org.apache.tamaya.format.ConfigurationFormat;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Implements a ini file format based on the APache Commons
+ * {@link org.apache.commons.configuration.HierarchicalINIConfiguration}.
+ */
+public class IniConfigurationFormat implements ConfigurationFormat {
+
+    @Override
+    public ConfigurationData readConfiguration(URL url) {
+        ConfigurationDataBuilder builder = ConfigurationDataBuilder.of(url, this);
+        try {
+            HierarchicalINIConfiguration commonIniConfiguration = new HierarchicalINIConfiguration(url);
+            for(String section:commonIniConfiguration.getSections()){
+                SubnodeConfiguration sectionConfig = commonIniConfiguration.getSection(section);
+                Map<String, String> properties = new HashMap<>();
+                Iterator<String> keyIter = sectionConfig.getKeys();
+                while(keyIter.hasNext()){
+                    String key = keyIter.next();
+                    properties.put(key, sectionConfig.getString(key));
+                }
+                builder.addProperties(section, properties);
+            }
+        } catch (ConfigurationException e) {
+            throw new ConfigException("Failed to parse ini-file format from " + url, e);
+        }
+        return builder.build();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bd997069/modules/integration/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/pom.xml b/modules/integration/pom.xml
index efc019d..105e0ac 100644
--- a/modules/integration/pom.xml
+++ b/modules/integration/pom.xml
@@ -23,7 +23,7 @@ under the License.
     <parent>
         <artifactId>tamaya-extensions-all</artifactId>
         <groupId>org.apache.tamaya.ext</groupId>
-        <version>0.1-SNAPSHOT</version>
+        <version>0.1-incubating-SNAPSHOT</version>
         <relativePath>..</relativePath>
     </parent>
     <packaging>pom</packaging>
@@ -34,6 +34,7 @@ under the License.
     <modules>
         <module>cdi</module>
         <module>se</module>
+        <module>commons</module>
     </modules>
 
 </project>
\ No newline at end of file


Mime
View raw message