tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [12/16] incubator-tamaya git commit: Created sandbox directory.
Date Tue, 24 Mar 2015 21:20:29 GMT
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f3d68c07/sandbox/integration/commons/src/main/java/org/apache/tamaya/integration/commons/CommonsConfigPropertySource.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/commons/src/main/java/org/apache/tamaya/integration/commons/CommonsConfigPropertySource.java
b/sandbox/integration/commons/src/main/java/org/apache/tamaya/integration/commons/CommonsConfigPropertySource.java
new file mode 100644
index 0000000..b2f2e82
--- /dev/null
+++ b/sandbox/integration/commons/src/main/java/org/apache/tamaya/integration/commons/CommonsConfigPropertySource.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.integration.commons;
+
+//X TODO Move out into separate commons-config integration module...
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * PropertySource that wraps {@link org.apache.commons.configuration.Configuration}.
+ */
+public class CommonsConfigPropertySource implements PropertySource {
+
+    private Configuration commonsConfig;
+    private int ordinal;
+    private String name;
+
+    public CommonsConfigPropertySource(int ordinal, String name, Configuration commonsConfig)
{
+        this.commonsConfig = Objects.requireNonNull(commonsConfig);
+        this.ordinal = ordinal;
+        this.name = Objects.requireNonNull(name);
+    }
+
+    public CommonsConfigPropertySource(String name, Configuration commonsConfig) {
+        commonsConfig = Objects.requireNonNull(commonsConfig);
+        this.name = Objects.requireNonNull(name);
+        try {
+            this.ordinal = commonsConfig.getInt(PropertySource.TAMAYA_ORDINAL);
+        } catch (Exception e) {
+            this.ordinal = 0;
+        }
+    }
+
+    @Override
+    public int getOrdinal() {
+        return ordinal;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public String get(String key) {
+        return commonsConfig.getString(key);
+    }
+
+    @Override
+    public Map<String, String> getProperties() {
+        Map<String, String> config = new HashMap<>();
+        Iterator<String> keyIter = commonsConfig.getKeys();
+        while (keyIter.hasNext()) {
+            String key = keyIter.next();
+            config.put(key, commonsConfig.getString(key));
+        }
+        return config;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f3d68c07/sandbox/integration/commons/src/main/java/org/apache/tamaya/integration/commons/IniConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/commons/src/main/java/org/apache/tamaya/integration/commons/IniConfigurationFormat.java
b/sandbox/integration/commons/src/main/java/org/apache/tamaya/integration/commons/IniConfigurationFormat.java
new file mode 100644
index 0000000..2f80977
--- /dev/null
+++ b/sandbox/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/f3d68c07/sandbox/integration/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/integration/pom.xml b/sandbox/integration/pom.xml
new file mode 100644
index 0000000..145988d
--- /dev/null
+++ b/sandbox/integration/pom.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy current the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>tamaya-sandbox</artifactId>
+        <groupId>org.apache.tamaya.ext</groupId>
+        <version>0.1-incubating-SNAPSHOT</version>
+        <relativePath>..</relativePath>
+    </parent>
+    <packaging>pom</packaging>
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.tamaya.ext.integration</groupId>
+    <artifactId>tamaya-integrations</artifactId>
+
+    <modules>
+        <module>cdi</module>
+        <module>se</module>
+        <module>commons</module>
+    </modules>
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f3d68c07/sandbox/management/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/management/pom.xml b/sandbox/management/pom.xml
new file mode 100644
index 0000000..1c18af0
--- /dev/null
+++ b/sandbox/management/pom.xml
@@ -0,0 +1,41 @@
+<!-- 
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy current the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.tamaya.ext</groupId>
+        <artifactId>tamaya-sandbox</artifactId>
+        <version>0.1-incubating-SNAPSHOT</version>
+        <relativePath>..</relativePath>
+    </parent>
+    <artifactId>tamaya-management</artifactId>
+    <name>Apache Tamaya Modules Integration - Java Management Extensions</name>
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>tamaya-core</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+</project>


Mime
View raw message