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 2015/11/25 08:17:45 UTC

[1/4] incubator-tamaya git commit: Fixed OSGI service integration.

Repository: incubator-tamaya
Updated Branches:
  refs/heads/master dce045d86 -> 9d10e2548


Fixed OSGI service integration.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/cb3eef4f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/cb3eef4f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/cb3eef4f

Branch: refs/heads/master
Commit: cb3eef4f158aeaee1cfea3a16566430bbb66955b
Parents: dce045d
Author: anatole <an...@apache.org>
Authored: Tue Nov 24 22:57:28 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Tue Nov 24 22:57:28 2015 +0100

----------------------------------------------------------------------
 .../tamaya/core/internal/OSGIActivator.java     |  7 ++-
 .../core/internal/OSGIServiceContext.java       |  2 +-
 .../tamaya/core/internal/OSGIServiceLoader.java | 62 ++++++++++++--------
 3 files changed, 44 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/cb3eef4f/core/src/main/java/org/apache/tamaya/core/internal/OSGIActivator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/OSGIActivator.java b/core/src/main/java/org/apache/tamaya/core/internal/OSGIActivator.java
index 3d80cd2..8a54d35 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/OSGIActivator.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/OSGIActivator.java
@@ -24,18 +24,23 @@ import org.apache.tamaya.spi.ServiceContextManager;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 
+import java.util.logging.Logger;
+
 /**
  * A bundle activator that registers the {@link OSGIServiceLoader}.
  */
 public class OSGIActivator implements BundleActivator {
 
+    private static final Logger LOG = Logger.getLogger(OSGIActivator.class.getName());
+
     private OSGIServiceLoader serviceLoader;
 
     @Override
     public void start(BundleContext context) {
         // Register marker service
         ServiceContextManager.set(new OSGIServiceContext(context));
-        serviceLoader =new OSGIServiceLoader();
+        LOG.info("Registered OSGI enabled ServiceContext...");
+        serviceLoader = new OSGIServiceLoader();
         context.addBundleListener(serviceLoader);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/cb3eef4f/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java b/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
index d4be430..083cd54 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
@@ -65,7 +65,7 @@ public class OSGIServiceContext implements ServiceContext{
     public <T> List<T> getServices(Class<T> serviceType) {
         List<ServiceReference<T>> refs = new ArrayList<>();
         try {
-            refs.addAll(this.bundleContext.getServiceReferences(serviceType, "*"));
+            refs.addAll(this.bundleContext.getServiceReferences(serviceType, null));
             Collections.sort(refs, REF_COMPARATOR);
             List<T> services = new ArrayList<>(refs.size());
             for(ServiceReference<T> ref:refs){

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/cb3eef4f/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java b/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java
index 90b0e26..d2a11e2 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java
@@ -22,8 +22,11 @@ import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URL;
+import java.util.ConcurrentModificationException;
 import java.util.Enumeration;
 import java.util.Hashtable;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -34,21 +37,23 @@ import org.osgi.framework.BundleListener;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
 
 /**
  * An bundle listener that registers services defined in META-INF/services, when a bundle is starting.
  *
  * @author anatole@apache.org
  */
-public class OSGIServiceLoader implements BundleListener
-{
+public class OSGIServiceLoader implements BundleListener {
     // Provide logging
     private static final Logger log = Logger.getLogger(OSGIServiceLoader.class.getName());
 
+    private Map<Class, ServiceTracker<Object,Object>> services = new ConcurrentHashMap<>();
+
     @Override
     public void bundleChanged(BundleEvent bundleEvent) {
         // Parse and create metadta on STARTING
-        if (bundleEvent.getType() == BundleEvent.STARTING) {
+        if (bundleEvent.getType() == BundleEvent.STARTED) {
             Bundle bundle = bundleEvent.getBundle();
             if (bundle.getEntry("META-INF/services/") == null) {
                 return;
@@ -76,32 +81,39 @@ public class OSGIServiceLoader implements BundleListener
             while (implClassName != null){
                 int hashIndex = implClassName.indexOf("#");
                 if (hashIndex > 0) {
-                    implClassName = implClassName.substring(0, hashIndex);
+                    implClassName = implClassName.substring(0, hashIndex-1);
+                }
+                else if (hashIndex == 0) {
+                    implClassName = "";
                 }
-
                 implClassName = implClassName.trim();
-
                 if (implClassName.length() > 0) {
-                    // Load the service class
-                    Class<?> implClass = (Class<?>)bundle.loadClass(implClassName);
-                    if (serviceClass.isAssignableFrom(implClass) == false) {
-                        log.warning("Configured service: " + implClassName + " is not assignble to " +
-                                serviceClass.getName());
-                        continue;
-                    }
-                    // Provide service properties
-                    Hashtable<String, String> props = new Hashtable<String, String>();
-                    props.put(Constants.VERSION_ATTRIBUTE, bundle.getVersion().toString());
-                    String vendor = (String)bundle.getHeaders().get(Constants.BUNDLE_VENDOR);
-                    props.put(Constants.SERVICE_VENDOR, (vendor != null ? vendor : "anonymous"));
-                    // Translate annotated @Priority into a service ranking
-                    props.put(Constants.SERVICE_RANKING,
-                            String.valueOf(PriorityServiceComparator.getPriority(implClass)));
+                    try {
+                        // Load the service class
+                        Class<?> implClass = (Class<?>) bundle.loadClass(implClassName);
+                        if (serviceClass.isAssignableFrom(implClass) == false) {
+                            log.warning("Configured service: " + implClassName + " is not assignble to " +
+                                    serviceClass.getName());
+                            continue;
+                        }
+                        // Provide service properties
+                        Hashtable<String, String> props = new Hashtable<String, String>();
+                        props.put(Constants.VERSION_ATTRIBUTE, bundle.getVersion().toString());
+                        String vendor = (String) bundle.getHeaders().get(Constants.BUNDLE_VENDOR);
+                        props.put(Constants.SERVICE_VENDOR, (vendor != null ? vendor : "anonymous"));
+                        // Translate annotated @Priority into a service ranking
+                        props.put(Constants.SERVICE_RANKING,
+                                String.valueOf(PriorityServiceComparator.getPriority(implClass)));
 
-                    // Register the service factory on behalf of the intercepted bundle
-                   JDKUtilServiceFactory factory = new JDKUtilServiceFactory(implClass);
-                    BundleContext bundleContext = bundle.getBundleContext();
-                    bundleContext.registerService(serviceName, factory, props);
+                        // Register the service factory on behalf of the intercepted bundle
+                        JDKUtilServiceFactory factory = new JDKUtilServiceFactory(implClass);
+                        BundleContext bundleContext = bundle.getBundleContext();
+                        bundleContext.registerService(serviceName, factory, props);
+                    }
+                    catch(Exception e){
+                        log.log(Level.SEVERE,
+                                "Failed to load service class using ServiceLoader logic: " + implClassName, e);
+                    }
                 }
                 implClassName = br.readLine();
             }


[2/4] incubator-tamaya git commit: Added arquilian tests.

Posted by an...@apache.org.
Added arquilian tests.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/41132393
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/41132393
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/41132393

Branch: refs/heads/master
Commit: 411323931a542ac49ec01e0670ef7ffb536d154e
Parents: cb3eef4
Author: anatole <an...@apache.org>
Authored: Wed Nov 25 08:15:39 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Nov 25 08:15:39 2015 +0100

----------------------------------------------------------------------
 .../tamaya/integration/osgi/base/Activator.java |  65 ++++++++
 .../osgi/base/TamayaConfigAdminImpl.java        | 156 +++++++++++++++++++
 .../osgi/base/TamayaConfigurationImpl.java      | 120 ++++++++++++++
 .../osgi/general/TamayaConfigAdminImpl.java     | 156 -------------------
 .../osgi/general/TamayaConfigurationImpl.java   | 120 --------------
 .../osgi/base/TestConfigIntegration.java        | 134 ++++++++++++++++
 .../META-INF/javaconfiguration.properties       |  18 +++
 .../general/src/test/resource/arquilian.xml     |  27 ++++
 .../general/src/test/resource/felix.properties  |  18 +++
 9 files changed, 538 insertions(+), 276 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/41132393/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/base/Activator.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/base/Activator.java b/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/base/Activator.java
new file mode 100644
index 0000000..e015a47
--- /dev/null
+++ b/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/base/Activator.java
@@ -0,0 +1,65 @@
+/*
+ * 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.osgi.base;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+/**
+ * Activator that registers the Tamaya based Service Class for {@link ConfigurationAdmin},
+ * using a default service priority of {@code 0}.
+ */
+public class Activator implements BundleActivator {
+
+    private static final String SERVICE_RANKING_PROP = "org.tamaya.integration.cm.ranking";
+
+    private static final Integer DEFAULT_RANKING = Integer.MIN_VALUE + 100;
+
+    private BundleContext context;
+
+    ServiceRegistration<ConfigurationAdmin> registration;
+
+    @Override
+    public void start(BundleContext context) throws Exception {
+        Dictionary<String,Object> props = new Hashtable<>();
+        String ranking = context.getProperty(SERVICE_RANKING_PROP);
+        if (ranking == null) {
+            props.put(Constants.SERVICE_RANKING, DEFAULT_RANKING);
+        } else{
+            props.put(Constants.SERVICE_RANKING, Integer.valueOf(ranking));
+        }
+        this.context = context;
+        TamayaConfigAdminImpl cm = new TamayaConfigAdminImpl(context);
+        registration = context.registerService(ConfigurationAdmin.class, cm, null);
+    }
+
+    @Override
+    public void stop(BundleContext context) throws Exception {
+        if (registration != null) {
+            registration.unregister();
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/41132393/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/base/TamayaConfigAdminImpl.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/base/TamayaConfigAdminImpl.java b/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/base/TamayaConfigAdminImpl.java
new file mode 100644
index 0000000..389c267
--- /dev/null
+++ b/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/base/TamayaConfigAdminImpl.java
@@ -0,0 +1,156 @@
+/*
+ * 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.osgi.base;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.cm.ManagedService;
+import org.osgi.service.cm.ManagedServiceFactory;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * Tamaya based implementation of an OSGI {@link ConfigurationAdmin}.
+ */
+public class TamayaConfigAdminImpl implements ConfigurationAdmin {
+    private final BundleContext context;
+    private ConfigurationAdmin parent;
+    private Map<String,Configuration> configs = new ConcurrentHashMap<>();
+    private static final Logger LOG = Logger.getLogger(TamayaConfigAdminImpl.class.getName());
+
+    public TamayaConfigAdminImpl(BundleContext context) throws IOException {
+        this.context = context;
+        ServiceReference<ConfigurationAdmin> ref = context.getServiceReference(ConfigurationAdmin.class);
+        this.parent = context.getService(ref);
+        ServiceTracker<ManagedService, ManagedService> serviceTracker = new ServiceTracker<ManagedService,
+                ManagedService>(context, ManagedService.class, null) {
+            @Override
+            public ManagedService addingService(ServiceReference<ManagedService> reference) {
+                ManagedService service = context.getService(reference);
+                Object pidObj = reference.getProperty(Constants.SERVICE_PID);
+                if (pidObj instanceof String) {
+                    String pid = (String) pidObj;
+                    try {
+                        Configuration config = getConfiguration(pid);
+                        if(config==null){
+                            service.updated(null);
+                        } else{
+                            service.updated(config.getProperties());
+                        }
+                    } catch (Exception e) {
+                        LOG.log(Level.WARNING, "Error configuring ManagedService: " + service, e);
+                    }
+                } else {
+                    LOG.log(Level.SEVERE, "Unsupported pid: " + pidObj);
+                }
+                return service;
+            }
+
+            @Override
+            public void removedService(ServiceReference<ManagedService> reference, ManagedService service) {
+                context.ungetService(reference);
+            }
+        };
+        serviceTracker.open();
+
+        ServiceTracker<ServiceFactory, ServiceFactory> factoryTracker
+                = new ServiceTracker<ServiceFactory, ServiceFactory>(context, ServiceFactory.class, null) {
+            @Override
+            public ServiceFactory addingService(ServiceReference<ServiceFactory> reference) {
+                ServiceFactory factory = context.getService(reference);
+                if(factory instanceof ManagedServiceFactory) {
+                    Object pidObj = reference.getProperty(Constants.SERVICE_PID);
+                    if (pidObj instanceof String) {
+                        String pid = (String) pidObj;
+                        try {
+                            Configuration config = getConfiguration(pid);
+                            if (config != null) {
+                                ((ManagedServiceFactory) factory).updated(config.getFactoryPid(), config.getProperties());
+                            }
+                        } catch (Exception e) {
+                            LOG.log(Level.WARNING, "Error configuring ManagedServiceFactory: " + factory, e);
+                        }
+                    } else {
+                        LOG.log(Level.SEVERE, "Unsupported pid: " + pidObj);
+                    }
+                }
+                return factory;
+            }
+
+            @Override
+            public void removedService(ServiceReference<ServiceFactory> reference, ServiceFactory service) {
+                super.removedService(reference, service);
+            }
+        };
+        factoryTracker.open();
+
+
+    }
+
+    @Override
+    public Configuration createFactoryConfiguration(String factoryPid) throws IOException {
+        return createFactoryConfiguration(factoryPid, null);
+    }
+
+    @Override
+    public Configuration createFactoryConfiguration(String factoryPid, String location) throws IOException {
+        return new TamayaConfigurationImpl(factoryPid, null, this.parent);
+    }
+
+    @Override
+    public Configuration getConfiguration(String pid, String location) throws IOException {
+        return getConfiguration(pid);
+    }
+
+    @Override
+    public Configuration getConfiguration(String pid) throws IOException {
+        return new TamayaConfigurationImpl(pid, null, this.parent);
+    }
+
+    @Override
+    public Configuration[] listConfigurations(String filter) throws IOException, InvalidSyntaxException {
+        Collection<Configuration> result;
+        if (filter == null) {
+            result = this.configs.values();
+        } else {
+            result = new ArrayList<>();
+            Filter flt = context.createFilter(filter);
+            for (Configuration config : this.configs.values()) {
+                if (flt.match(config.getProperties())) {
+                    result.add(config);
+                }
+            }
+        }
+        return result.isEmpty() ? null : result.toArray(new Configuration[configs.size()]);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/41132393/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/base/TamayaConfigurationImpl.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/base/TamayaConfigurationImpl.java b/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/base/TamayaConfigurationImpl.java
new file mode 100644
index 0000000..8c7a747
--- /dev/null
+++ b/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/base/TamayaConfigurationImpl.java
@@ -0,0 +1,120 @@
+/*
+ * 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.osgi.base;
+
+import java.io.IOException;
+import java.util.*;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.functions.PropertyMatcher;
+import org.apache.tamaya.functions.ConfigurationFunctions;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/**
+ * Tamaya based implementation of an OSGI {@link Configuration}.
+ */
+public class TamayaConfigurationImpl implements Configuration {
+    private final String pid;
+    private final String factoryPid;
+    private Map<String, String> properties = new HashMap<>();
+    private org.apache.tamaya.Configuration config;
+
+    public TamayaConfigurationImpl(String confPid, String factoryPid, ConfigurationAdmin parent) {
+        this.pid = confPid;
+        this.factoryPid = factoryPid;
+        if(parent!=null){
+            try {
+                Dictionary<String, Object> conf = parent.getConfiguration(confPid, factoryPid).getProperties();
+                Enumeration<String> keys = conf.keys();
+                while(keys.hasMoreElements()){
+                    String key = keys.nextElement();
+                    this.properties.put(key, conf.get(key).toString());
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        this.config = ConfigurationProvider.getConfiguration();
+        this.properties.putAll(
+                config.with(ConfigurationFunctions.filter(new PropertyMatcher() {
+                    @Override
+                    public boolean test(String key, String value) {
+                        // TODO define name space / SPI
+                        if (key.startsWith("bundle." + pid)) {
+                            return true;
+                        }
+                        return false;
+            }
+        })).getProperties());
+    }
+
+    @Override
+    public String getPid() {
+        return pid;
+    }
+
+    @Override
+    public Dictionary<String, Object> getProperties() {
+        return new Hashtable<String, Object>(properties);
+    }
+
+    @Override
+    public void update(Dictionary<String, ?> properties) throws IOException {
+        throw new UnsupportedOperationException("Nuatability not yet supported.");
+         // ConfigChangeProvider.createChangeRequest(this.config)
+    }
+
+    @Override
+    public void delete() throws IOException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public String getFactoryPid() {
+        return factoryPid;
+    }
+
+    @Override
+    public void update() throws IOException {
+        this.config = ConfigurationProvider.getConfiguration();
+        this.properties = config.with(ConfigurationFunctions.filter(new PropertyMatcher() {
+            @Override
+            public boolean test(String key, String value) {
+// TODO define name space / SPI
+                return false;
+            }
+        })).getProperties();
+    }
+
+    @Override
+    public void setBundleLocation(String location) {
+    }
+
+    @Override
+    public String getBundleLocation() {
+        return null;
+    }
+
+    @Override
+    public long getChangeCount() {
+        return 0;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/41132393/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/general/TamayaConfigAdminImpl.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/general/TamayaConfigAdminImpl.java b/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/general/TamayaConfigAdminImpl.java
deleted file mode 100644
index 8454e08..0000000
--- a/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/general/TamayaConfigAdminImpl.java
+++ /dev/null
@@ -1,156 +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.integration.osgi.general;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceFactory;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.cm.ManagedService;
-import org.osgi.service.cm.ManagedServiceFactory;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * Tamaya based implementation of an OSGI {@link ConfigurationAdmin}.
- */
-public class TamayaConfigAdminImpl implements ConfigurationAdmin {
-    private final BundleContext context;
-    private ConfigurationAdmin parent;
-    private Map<String,Configuration> configs = new ConcurrentHashMap<>();
-    private static final Logger LOG = Logger.getLogger(TamayaConfigAdminImpl.class.getName());
-
-    public TamayaConfigAdminImpl(BundleContext context) throws IOException {
-        this.context = context;
-        ServiceReference<ConfigurationAdmin> ref = context.getServiceReference(ConfigurationAdmin.class);
-        this.parent = context.getService(ref);
-        ServiceTracker<ManagedService, ManagedService> serviceTracker = new ServiceTracker<ManagedService,
-                ManagedService>(context, ManagedService.class, null) {
-            @Override
-            public ManagedService addingService(ServiceReference<ManagedService> reference) {
-                ManagedService service = context.getService(reference);
-                Object pidObj = reference.getProperty(Constants.SERVICE_PID);
-                if (pidObj instanceof String) {
-                    String pid = (String) pidObj;
-                    try {
-                        Configuration config = getConfiguration(pid);
-                        if(config==null){
-                            service.updated(null);
-                        } else{
-                            service.updated(config.getProperties());
-                        }
-                    } catch (Exception e) {
-                        LOG.log(Level.WARNING, "Error configuring ManagedService: " + service, e);
-                    }
-                } else {
-                    LOG.log(Level.SEVERE, "Unsupported pid: " + pidObj);
-                }
-                return service;
-            }
-
-            @Override
-            public void removedService(ServiceReference<ManagedService> reference, ManagedService service) {
-                context.ungetService(reference);
-            }
-        };
-        serviceTracker.open();
-
-        ServiceTracker<ServiceFactory, ServiceFactory> factoryTracker
-                = new ServiceTracker<ServiceFactory, ServiceFactory>(context, ServiceFactory.class, null) {
-            @Override
-            public ServiceFactory addingService(ServiceReference<ServiceFactory> reference) {
-                ServiceFactory factory = context.getService(reference);
-                if(factory instanceof ManagedServiceFactory) {
-                    Object pidObj = reference.getProperty(Constants.SERVICE_PID);
-                    if (pidObj instanceof String) {
-                        String pid = (String) pidObj;
-                        try {
-                            Configuration config = getConfiguration(pid);
-                            if (config != null) {
-                                ((ManagedServiceFactory) factory).updated(config.getFactoryPid(), config.getProperties());
-                            }
-                        } catch (Exception e) {
-                            LOG.log(Level.WARNING, "Error configuring ManagedServiceFactory: " + factory, e);
-                        }
-                    } else {
-                        LOG.log(Level.SEVERE, "Unsupported pid: " + pidObj);
-                    }
-                }
-                return factory;
-            }
-
-            @Override
-            public void removedService(ServiceReference<ServiceFactory> reference, ServiceFactory service) {
-                super.removedService(reference, service);
-            }
-        };
-        factoryTracker.open();
-
-
-    }
-
-    @Override
-    public Configuration createFactoryConfiguration(String factoryPid) throws IOException {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public Configuration createFactoryConfiguration(String factoryPid, String location) throws IOException {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public Configuration getConfiguration(String pid, String location) throws IOException {
-        return getConfiguration(pid);
-    }
-
-    @Override
-    public Configuration getConfiguration(String pid) throws IOException {
-        return new TamayaConfigurationImpl(pid, null, this.parent);
-    }
-
-    @Override
-    public Configuration[] listConfigurations(String filter) throws IOException, InvalidSyntaxException {
-        Collection<Configuration> result;
-        if (filter == null) {
-            result = this.configs.values();
-        } else {
-            result = new ArrayList<>();
-            Filter flt = context.createFilter(filter);
-            for (Configuration config : this.configs.values()) {
-                if (flt.match(config.getProperties())) {
-                    result.add(config);
-                }
-            }
-        }
-        return result.isEmpty() ? null : result.toArray(new Configuration[configs.size()]);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/41132393/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/general/TamayaConfigurationImpl.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/general/TamayaConfigurationImpl.java b/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/general/TamayaConfigurationImpl.java
deleted file mode 100644
index 1a47611..0000000
--- a/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/general/TamayaConfigurationImpl.java
+++ /dev/null
@@ -1,120 +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.integration.osgi.general;
-
-import java.io.IOException;
-import java.util.*;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.functions.PropertyMatcher;
-import org.apache.tamaya.functions.ConfigurationFunctions;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-
-/**
- * Tamaya based implementation of an OSGI {@link Configuration}.
- */
-public class TamayaConfigurationImpl implements Configuration {
-    private final String pid;
-    private final String factoryPid;
-    private Map<String, String> properties = new HashMap<>();
-    private org.apache.tamaya.Configuration config;
-
-    public TamayaConfigurationImpl(String confPid, String factoryPid, ConfigurationAdmin parent) {
-        this.pid = confPid;
-        this.factoryPid = factoryPid;
-        if(parent!=null){
-            try {
-                Dictionary<String, Object> conf = parent.getConfiguration(confPid, factoryPid).getProperties();
-                Enumeration<String> keys = conf.keys();
-                while(keys.hasMoreElements()){
-                    String key = keys.nextElement();
-                    this.properties.put(key, conf.get(key).toString());
-                }
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        }
-        this.config = ConfigurationProvider.getConfiguration();
-        this.properties.putAll(
-                config.with(ConfigurationFunctions.filter(new PropertyMatcher() {
-                    @Override
-                    public boolean test(String key, String value) {
-                        // TODO define name space / SPI
-                        if (key.startsWith("bundle." + pid)) {
-                            return true;
-                        }
-                        return false;
-            }
-        })).getProperties());
-    }
-
-    @Override
-    public String getPid() {
-        return pid;
-    }
-
-    @Override
-    public Dictionary<String, Object> getProperties() {
-        return new Hashtable<String, Object>(properties);
-    }
-
-    @Override
-    public void update(Dictionary<String, ?> properties) throws IOException {
-        throw new UnsupportedOperationException("Nuatability not yet supported.");
-         // ConfigChangeProvider.createChangeRequest(this.config)
-    }
-
-    @Override
-    public void delete() throws IOException {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public String getFactoryPid() {
-        return factoryPid;
-    }
-
-    @Override
-    public void update() throws IOException {
-        this.config = ConfigurationProvider.getConfiguration();
-        this.properties = config.with(ConfigurationFunctions.filter(new PropertyMatcher() {
-            @Override
-            public boolean test(String key, String value) {
-// TODO define name space / SPI
-                return false;
-            }
-        })).getProperties();
-    }
-
-    @Override
-    public void setBundleLocation(String location) {
-    }
-
-    @Override
-    public String getBundleLocation() {
-        return null;
-    }
-
-    @Override
-    public long getChangeCount() {
-        return 0;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/41132393/modules/integration/osgi/general/src/test/java/org/apache/tamaya/integration/osgi/base/TestConfigIntegration.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/general/src/test/java/org/apache/tamaya/integration/osgi/base/TestConfigIntegration.java b/modules/integration/osgi/general/src/test/java/org/apache/tamaya/integration/osgi/base/TestConfigIntegration.java
new file mode 100644
index 0000000..1e78bfa
--- /dev/null
+++ b/modules/integration/osgi/general/src/test/java/org/apache/tamaya/integration/osgi/base/TestConfigIntegration.java
@@ -0,0 +1,134 @@
+/*
+ * 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.osgi.base;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.spi.ServiceContext;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.OperateOnDeployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.osgi.metadata.OSGiManifestBuilder;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.Asset;
+import org.jboss.shrinkwrap.api.importer.ZipImporter;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.resolver.api.maven.Maven;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+import java.io.File;
+import java.io.InputStream;
+
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(Arquillian.class)
+public class TestConfigIntegration{
+
+    private static final String TAMAYA_VERSION = "0.2-incubating-SNAPSHOT";
+
+    @ArquillianResource BundleContext context;
+
+    //////////////////////////////////////////////////////// Test setup //////////////////////////////////
+
+    @Deployment(order=11)
+    public static JavaArchive createdeployment() {
+        final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "tamaya-osgi-base.jar");
+        archive.setManifest(new Asset() {
+            public InputStream openStream() {
+                OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
+                builder.addBundleSymbolicName(archive.getName());
+                builder.addBundleManifestVersion(2);
+                builder.addImportPackages("org.junit", "org.apache.tamaya", "org.apache.tamaya.spi", "org.apache.tamaya.core");
+                builder.addImportPackages(ServiceContext.class, ConfigurationProvider.class);
+//                builder.addBundleActivator(Activator.class);
+                return builder.openStream();
+            }
+        });
+        archive.addClasses(TestConfigIntegration.class);
+//        archive.addAsResource("META-INF/javaconfiguration.properties");
+        return archive;
+    }
+
+    @Deployment(name="felix.main",order=10)
+    public static JavaArchive deployMain() {
+        return ShrinkWrap.create(ZipImporter.class, "felix.main-5.4.0.jar")
+                .importFrom(new File("src/container/org.apache.felix.main-5.4.0.jar"))
+                .as(JavaArchive.class);
+    }
+
+    @Deployment(name="tamaya-api",order=1)
+    public static JavaArchive deployTamayaAPI() {
+        return ShrinkWrap.create(ZipImporter.class, "tamaya-api.jar")
+                .importFrom(getBundleFile("tamaya-api:"+TAMAYA_VERSION))
+                .as(JavaArchive.class);
+    }
+
+    @Deployment(name="tamaya-core",order=2)
+    public static JavaArchive deployTamayaCore() {
+        return ShrinkWrap.create(ZipImporter.class, "tamaya-core.jar")
+                .importFrom(getBundleFile("tamaya-core:"+TAMAYA_VERSION))
+                .as(JavaArchive.class);
+    }
+
+    @Deployment(name="javax.annotation",order=0)
+    public static JavaArchive deployJavaxAnnotation() {
+        return ShrinkWrap.create(ZipImporter.class, "javax.annotation.jar")
+                .importFrom(Maven.configureResolver()
+                        .withMavenCentralRepo(false)
+                        .withClassPathResolution(true)
+                        .resolve("org.apache.geronimo.specs:geronimo-annotation_1.2_spec:1.0-alpha-1")
+                        .withoutTransitivity().asSingleFile())
+                .as(JavaArchive.class);
+    }
+
+    private static File getBundleFile(String artifactId) {
+        // Check
+        return Maven.configureResolver()
+                .withMavenCentralRepo(false)
+                .withClassPathResolution(true)
+                .resolve("org.apache.tamaya:" + artifactId).withoutTransitivity().asSingleFile();
+    }
+
+
+    //////////////////////////////////////////////////////// Tests //////////////////////////////////
+
+
+//    @Before
+//    public void startBundles(){
+//        for(Bundle bundle:context.getBundles()) {
+//            try {
+//                bundle.start();
+//            } catch (BundleException e) {
+//                e.printStackTrace();
+//            }
+//        }
+//    }
+
+    @OperateOnDeployment("_DEFAULT_")
+    @Test
+    public void testTamayaAvailable() throws Exception {
+        assertNotNull(ConfigurationProvider.getConfiguration());
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/41132393/modules/integration/osgi/general/src/test/resource/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/general/src/test/resource/META-INF/javaconfiguration.properties b/modules/integration/osgi/general/src/test/resource/META-INF/javaconfiguration.properties
new file mode 100644
index 0000000..b2b0d69
--- /dev/null
+++ b/modules/integration/osgi/general/src/test/resource/META-INF/javaconfiguration.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+__tamaya-test__.tamaya-test-property=success!
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/41132393/modules/integration/osgi/general/src/test/resource/arquilian.xml
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/general/src/test/resource/arquilian.xml b/modules/integration/osgi/general/src/test/resource/arquilian.xml
new file mode 100644
index 0000000..d036dca
--- /dev/null
+++ b/modules/integration/osgi/general/src/test/resource/arquilian.xml
@@ -0,0 +1,27 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy current the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+
+    <container qualifier="jboss" default="true">
+        <configuration>
+            <property name="frameworkProperties">/felix.properties</property>
+        </configuration>
+    </container>
+</arquillian>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/41132393/modules/integration/osgi/general/src/test/resource/felix.properties
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/general/src/test/resource/felix.properties b/modules/integration/osgi/general/src/test/resource/felix.properties
new file mode 100644
index 0000000..f81f6bc
--- /dev/null
+++ b/modules/integration/osgi/general/src/test/resource/felix.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.osgi.framework.bootdelegation=org.osgi.service.cm;org.apache.felix.cm;org.apache.tamaya;org.apache.tamaya.spi;*
\ No newline at end of file



[4/4] incubator-tamaya git commit: TAMAYA-129: OSGI Support. Partially tested.

Posted by an...@apache.org.
TAMAYA-129: OSGI Support. Partially tested.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/9d10e254
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/9d10e254
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/9d10e254

Branch: refs/heads/master
Commit: 9d10e25489bfa4d48c6e820f8672b3df0d8806d1
Parents: 4113239
Author: anatole <an...@apache.org>
Authored: Wed Nov 25 08:17:23 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Nov 25 08:17:23 2015 +0100

----------------------------------------------------------------------
 modules/integration/osgi/felix/pom.xml          |   4 +-
 .../tamaya/integration/osgi/base/Activator.java |  61 ++
 .../osgi/base/ConfigurationHandler.java         | 757 +++++++++++++++++++
 .../osgi/base/TamayaPersistenceManager.java     | 128 ++++
 .../integration/osgi/felix/Activator.java       |  61 --
 .../osgi/felix/ConfigurationHandler.java        | 757 -------------------
 .../osgi/felix/TamayaPersistenceManager.java    | 128 ----
 .../osgi/base/TestConfigIntegration.java        | 173 +++++
 .../osgi/felix/TestConfigIntegration.java       | 173 -----
 modules/integration/osgi/general/pom.xml        |  31 +
 .../integration/osgi/general/Activator.java     |  65 --
 .../integration/osgi/injection/Activator.java   |  40 +-
 12 files changed, 1187 insertions(+), 1191 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9d10e254/modules/integration/osgi/felix/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/pom.xml b/modules/integration/osgi/felix/pom.xml
index 85a7ea9..c79f410 100644
--- a/modules/integration/osgi/felix/pom.xml
+++ b/modules/integration/osgi/felix/pom.xml
@@ -50,10 +50,10 @@
                 <configuration>
                     <instructions>
                         <Bundle-Activator>
-                            org.apache.tamaya.integration.osgi.felix.Activator
+                            org.apache.tamaya.integration.osgi.base.Activator
                         </Bundle-Activator>
                         <Private-Package>
-                            org.apache.tamaya.integration.osgi.felix
+                            org.apache.tamaya.integration.osgi.base
                         </Private-Package>
                         <Export-Service>
                             org.apache.felix.cm.PersistenceManager

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9d10e254/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/base/Activator.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/base/Activator.java b/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/base/Activator.java
new file mode 100644
index 0000000..1bf291b
--- /dev/null
+++ b/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/base/Activator.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.integration.osgi.base;
+
+import org.apache.felix.cm.PersistenceManager;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+import java.util.Hashtable;
+
+/**
+ * Activator that registers the Tamaya implementation of {@link org.apache.felix.cm.PersistenceManager},
+ * hereby overriding the version registered by felix CM by default.
+ */
+public class Activator implements BundleActivator{
+
+    /**
+     * Our registration, used on stop.
+     */
+    private ServiceRegistration<PersistenceManager> pmRegistration;
+
+
+    @Override
+    public void start(BundleContext bundleContext) throws Exception {
+        TamayaPersistenceManager tpm = new TamayaPersistenceManager(bundleContext);
+        Hashtable props = new Hashtable();
+        props.put( Constants.SERVICE_PID, tpm.getClass().getName() );
+        props.put( Constants.SERVICE_DESCRIPTION, "Apache Tamaya Persistence Manager" );
+        props.put( Constants.SERVICE_VENDOR, "Apache Software Foundation" );
+        Integer ranking = 10;
+        // TODO Make ranking configurable...
+        props.put( Constants.SERVICE_RANKING, ranking );
+        pmRegistration = bundleContext.registerService( PersistenceManager.class, tpm, props );
+    }
+
+    @Override
+    public void stop(BundleContext bundleContext) throws Exception {
+        if(pmRegistration!=null){
+            pmRegistration.unregister();
+            pmRegistration = null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9d10e254/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/base/ConfigurationHandler.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/base/ConfigurationHandler.java b/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/base/ConfigurationHandler.java
new file mode 100644
index 0000000..48319f0
--- /dev/null
+++ b/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/base/ConfigurationHandler.java
@@ -0,0 +1,757 @@
+/*
+ * 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.osgi.base;
+
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PushbackReader;
+import java.io.Writer;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * The <code>ConfigurationHandler</code> class implements configuration reading
+ * form a <code>java.io.InputStream</code> and writing to a
+ * <code>java.io.OutputStream</code> on behalf of the
+ * {@link FilePersistenceManager} class.
+ * <p>
+ * <pre>
+ * cfg = prop &quot;=&quot; value .
+ *  prop = symbolic-name . // 1.4.2 of OSGi Core Specification
+ *  symbolic-name = token { &quot;.&quot; token } .
+ *  token = { [ 0..9 ] | [ a..z ] | [ A..Z ] | '_' | '-' } .
+ *  value = [ type ] ( &quot;[&quot; values &quot;]&quot; | &quot;(&quot; values &quot;)&quot; | simple ) .
+ *  values = simple { &quot;,&quot; simple } .
+ *  simple = &quot;&quot;&quot; stringsimple &quot;&quot;&quot; .
+ *  type = // 1-char type code .
+ *  stringsimple = // quoted string representation of the value .
+ * </pre>
+ */
+class ConfigurationHandler {
+    protected static final String ENCODING = "UTF-8";
+
+    protected static final int TOKEN_NAME = 'N';
+    protected static final int TOKEN_EQ = '=';
+    protected static final int TOKEN_ARR_OPEN = '[';
+    protected static final int TOKEN_ARR_CLOS = ']';
+    protected static final int TOKEN_VEC_OPEN = '(';
+    protected static final int TOKEN_VEC_CLOS = ')';
+    protected static final int TOKEN_COMMA = ',';
+    protected static final int TOKEN_VAL_OPEN = '"'; // '{';
+    protected static final int TOKEN_VAL_CLOS = '"'; // '}';
+
+    protected static final int TOKEN_COMMENT = '#';
+
+    // simple types (string & primitive wrappers)
+    protected static final int TOKEN_SIMPLE_STRING = 'T';
+    protected static final int TOKEN_SIMPLE_INTEGER = 'I';
+    protected static final int TOKEN_SIMPLE_LONG = 'L';
+    protected static final int TOKEN_SIMPLE_FLOAT = 'F';
+    protected static final int TOKEN_SIMPLE_DOUBLE = 'D';
+    protected static final int TOKEN_SIMPLE_BYTE = 'X';
+    protected static final int TOKEN_SIMPLE_SHORT = 'S';
+    protected static final int TOKEN_SIMPLE_CHARACTER = 'C';
+    protected static final int TOKEN_SIMPLE_BOOLEAN = 'B';
+
+    // primitives
+    protected static final int TOKEN_PRIMITIVE_INT = 'i';
+    protected static final int TOKEN_PRIMITIVE_LONG = 'l';
+    protected static final int TOKEN_PRIMITIVE_FLOAT = 'f';
+    protected static final int TOKEN_PRIMITIVE_DOUBLE = 'd';
+    protected static final int TOKEN_PRIMITIVE_BYTE = 'x';
+    protected static final int TOKEN_PRIMITIVE_SHORT = 's';
+    protected static final int TOKEN_PRIMITIVE_CHAR = 'c';
+    protected static final int TOKEN_PRIMITIVE_BOOLEAN = 'b';
+
+    protected static final String CRLF = "\r\n";
+    protected static final String INDENT = "  ";
+    protected static final String COLLECTION_LINE_BREAK = " \\\r\n";
+
+    protected static final Map CODE_2_TYPE;
+    protected static final Map TYPE_2_CODE;
+
+    // set of valid characters for "symblic-name"
+    private static final BitSet NAME_CHARS;
+    private static final BitSet TOKEN_CHARS;
+
+    static {
+        TYPE_2_CODE = new HashMap();
+
+        // simple (exclusive String whose type code is not written)
+        TYPE_2_CODE.put(Integer.class, new Integer(TOKEN_SIMPLE_INTEGER));
+        TYPE_2_CODE.put(Long.class, new Integer(TOKEN_SIMPLE_LONG));
+        TYPE_2_CODE.put(Float.class, new Integer(TOKEN_SIMPLE_FLOAT));
+        TYPE_2_CODE.put(Double.class, new Integer(TOKEN_SIMPLE_DOUBLE));
+        TYPE_2_CODE.put(Byte.class, new Integer(TOKEN_SIMPLE_BYTE));
+        TYPE_2_CODE.put(Short.class, new Integer(TOKEN_SIMPLE_SHORT));
+        TYPE_2_CODE.put(Character.class, new Integer(TOKEN_SIMPLE_CHARACTER));
+        TYPE_2_CODE.put(Boolean.class, new Integer(TOKEN_SIMPLE_BOOLEAN));
+
+        // primitives
+        TYPE_2_CODE.put(Integer.TYPE, new Integer(TOKEN_PRIMITIVE_INT));
+        TYPE_2_CODE.put(Long.TYPE, new Integer(TOKEN_PRIMITIVE_LONG));
+        TYPE_2_CODE.put(Float.TYPE, new Integer(TOKEN_PRIMITIVE_FLOAT));
+        TYPE_2_CODE.put(Double.TYPE, new Integer(TOKEN_PRIMITIVE_DOUBLE));
+        TYPE_2_CODE.put(Byte.TYPE, new Integer(TOKEN_PRIMITIVE_BYTE));
+        TYPE_2_CODE.put(Short.TYPE, new Integer(TOKEN_PRIMITIVE_SHORT));
+        TYPE_2_CODE.put(Character.TYPE, new Integer(TOKEN_PRIMITIVE_CHAR));
+        TYPE_2_CODE.put(Boolean.TYPE, new Integer(TOKEN_PRIMITIVE_BOOLEAN));
+
+        // reverse map to map type codes to classes, string class mapping
+        // to be added manually, as the string type code is not written and
+        // hence not included in the TYPE_2_CODE map
+        CODE_2_TYPE = new HashMap();
+        for (Iterator ti = TYPE_2_CODE.entrySet().iterator(); ti.hasNext(); ) {
+            Map.Entry entry = (Map.Entry) ti.next();
+            CODE_2_TYPE.put(entry.getValue(), entry.getKey());
+        }
+        CODE_2_TYPE.put(new Integer(TOKEN_SIMPLE_STRING), String.class);
+
+        NAME_CHARS = new BitSet();
+        for (int i = '0'; i <= '9'; i++) {
+            NAME_CHARS.set(i);
+        }
+        for (int i = 'a'; i <= 'z'; i++) {
+            NAME_CHARS.set(i);
+        }
+        for (int i = 'A'; i <= 'Z'; i++) {
+            NAME_CHARS.set(i);
+        }
+        NAME_CHARS.set('_');
+        NAME_CHARS.set('-');
+        NAME_CHARS.set('.');
+        NAME_CHARS.set('\\');
+
+        TOKEN_CHARS = new BitSet();
+        TOKEN_CHARS.set(TOKEN_EQ);
+        TOKEN_CHARS.set(TOKEN_ARR_OPEN);
+        TOKEN_CHARS.set(TOKEN_ARR_CLOS);
+        TOKEN_CHARS.set(TOKEN_VEC_OPEN);
+        TOKEN_CHARS.set(TOKEN_VEC_CLOS);
+        TOKEN_CHARS.set(TOKEN_COMMA);
+        TOKEN_CHARS.set(TOKEN_VAL_OPEN);
+        TOKEN_CHARS.set(TOKEN_VAL_CLOS);
+        TOKEN_CHARS.set(TOKEN_SIMPLE_STRING);
+        TOKEN_CHARS.set(TOKEN_SIMPLE_INTEGER);
+        TOKEN_CHARS.set(TOKEN_SIMPLE_LONG);
+        TOKEN_CHARS.set(TOKEN_SIMPLE_FLOAT);
+        TOKEN_CHARS.set(TOKEN_SIMPLE_DOUBLE);
+        TOKEN_CHARS.set(TOKEN_SIMPLE_BYTE);
+        TOKEN_CHARS.set(TOKEN_SIMPLE_SHORT);
+        TOKEN_CHARS.set(TOKEN_SIMPLE_CHARACTER);
+        TOKEN_CHARS.set(TOKEN_SIMPLE_BOOLEAN);
+
+        // primitives
+        TOKEN_CHARS.set(TOKEN_PRIMITIVE_INT);
+        TOKEN_CHARS.set(TOKEN_PRIMITIVE_LONG);
+        TOKEN_CHARS.set(TOKEN_PRIMITIVE_FLOAT);
+        TOKEN_CHARS.set(TOKEN_PRIMITIVE_DOUBLE);
+        TOKEN_CHARS.set(TOKEN_PRIMITIVE_BYTE);
+        TOKEN_CHARS.set(TOKEN_PRIMITIVE_SHORT);
+        TOKEN_CHARS.set(TOKEN_PRIMITIVE_CHAR);
+        TOKEN_CHARS.set(TOKEN_PRIMITIVE_BOOLEAN);
+    }
+
+
+    /**
+     * Writes the configuration data from the <code>Dictionary</code> to the
+     * given <code>OutputStream</code>.
+     * <p>
+     * This method writes at the current location in the stream and does not
+     * close the outputstream.
+     *
+     * @param out        The <code>OutputStream</code> to write the configurtion data
+     *                   to.
+     * @param properties The <code>Dictionary</code> to write.
+     * @throws IOException If an error occurrs writing to the output stream.
+     */
+    public static void write(OutputStream out, Dictionary properties) throws IOException {
+        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out, ENCODING));
+
+        for (Enumeration ce = orderedKeys(properties); ce.hasMoreElements(); ) {
+            String key = (String) ce.nextElement();
+
+            // cfg = prop "=" value "." .
+            writeQuoted(bw, key);
+            bw.write(TOKEN_EQ);
+            writeValue(bw, properties.get(key));
+            bw.write(CRLF);
+        }
+
+        bw.flush();
+    }
+
+    /**
+     * Generates an <code>Enumeration</code> for the given
+     * <code>Dictionary</code> where the keys of the <code>Dictionary</code>
+     * are provided in sorted order.
+     *
+     * @param properties The <code>Dictionary</code> that keys are sorted.
+     * @return An <code>Enumeration</code> that provides the keys of
+     * properties in an ordered manner.
+     */
+    private static Enumeration orderedKeys(Dictionary properties) {
+        String[] keyArray = new String[properties.size()];
+        int i = 0;
+        for (Enumeration ce = properties.keys(); ce.hasMoreElements(); ) {
+            keyArray[i] = (String) ce.nextElement();
+            i++;
+        }
+        Arrays.sort(keyArray);
+        return Collections.enumeration(Arrays.asList(keyArray));
+    }
+
+
+    /**
+     * Reads configuration data from the given <code>InputStream</code> and
+     * returns a new <code>Dictionary</code> object containing the data.
+     * <p>
+     * This method reads from the current location in the stream upto the end of
+     * the stream but does not close the stream at the end.
+     *
+     * @param ins The <code>InputStream</code> from which to read the
+     *            configuration data.
+     * @return A <code>Dictionary</code> object containing the configuration
+     * data. This object may be empty if the stream contains no
+     * configuration data.
+     * @throws IOException If an error occurrs reading from the stream. This exception
+     *                     is also thrown if a syntax error is encountered.
+     */
+    public static Dictionary read(InputStream ins) throws IOException {
+        return new ConfigurationHandler().readInternal(ins);
+    }
+
+
+    // private constructor, this class is not to be instantiated from the
+    // outside
+    private ConfigurationHandler() {
+    }
+
+    // ---------- Configuration Input Implementation ---------------------------
+
+    private int token;
+    private String tokenValue;
+    private int line;
+    private int pos;
+
+
+    private Dictionary readInternal(InputStream ins) throws IOException {
+        BufferedReader br = new BufferedReader(new InputStreamReader(ins, ENCODING));
+        PushbackReader pr = new PushbackReader(br, 1);
+
+        token = 0;
+        tokenValue = null;
+        line = 0;
+        pos = 0;
+
+        Hashtable configuration = new Hashtable();
+        token = 0;
+        while (nextToken(pr, true) == TOKEN_NAME) {
+            String key = tokenValue;
+
+            // expect equal sign
+            if (nextToken(pr, false) != TOKEN_EQ) {
+                throw readFailure(token, TOKEN_EQ);
+            }
+
+            // expect the token value
+            Object value = readValue(pr);
+            if (value != null) {
+                configuration.put(key, value);
+            }
+        }
+
+        return configuration;
+    }
+
+
+    /**
+     * value = type ( "[" values "]" | "(" values ")" | simple ) . values =
+     * value { "," value } . simple = "{" stringsimple "}" . type = // 1-char
+     * type code . stringsimple = // quoted string representation of the value .
+     *
+     * @param pr
+     * @return
+     * @throws IOException
+     */
+    private Object readValue(PushbackReader pr) throws IOException {
+        // read (optional) type code
+        int type = read(pr);
+
+        // read value kind code if type code is not a value kinde code
+        int code;
+        if (CODE_2_TYPE.containsKey(new Integer(type))) {
+            code = read(pr);
+        } else {
+            code = type;
+            type = TOKEN_SIMPLE_STRING;
+        }
+
+        switch (code) {
+            case TOKEN_ARR_OPEN:
+                return readArray(type, pr);
+
+            case TOKEN_VEC_OPEN:
+                return readCollection(type, pr);
+
+            case TOKEN_VAL_OPEN:
+                Object value = readSimple(type, pr);
+                ensureNext(pr, TOKEN_VAL_CLOS);
+                return value;
+
+            default:
+                return null;
+        }
+    }
+
+
+    private Object readArray(int typeCode, PushbackReader pr) throws IOException {
+        List list = new ArrayList();
+        for (; ; ) {
+            int c = ignorablePageBreakAndWhiteSpace(pr);
+            if (c == TOKEN_VAL_OPEN) {
+                Object value = readSimple(typeCode, pr);
+                if (value == null) {
+                    // abort due to error
+                    return null;
+                }
+
+                ensureNext(pr, TOKEN_VAL_CLOS);
+
+                list.add(value);
+
+                c = ignorablePageBreakAndWhiteSpace(pr);
+            }
+
+            if (c == TOKEN_ARR_CLOS) {
+                Class type = (Class) CODE_2_TYPE.get(new Integer(typeCode));
+                Object array = Array.newInstance(type, list.size());
+                for (int i = 0; i < list.size(); i++) {
+                    Array.set(array, i, list.get(i));
+                }
+                return array;
+            } else if (c < 0) {
+                return null;
+            } else if (c != TOKEN_COMMA) {
+                return null;
+            }
+        }
+    }
+
+
+    private Collection readCollection(int typeCode, PushbackReader pr) throws IOException {
+        Collection collection = new ArrayList();
+        for (; ; ) {
+            int c = ignorablePageBreakAndWhiteSpace(pr);
+            if (c == TOKEN_VAL_OPEN) {
+                Object value = readSimple(typeCode, pr);
+                if (value == null) {
+                    // abort due to error
+                    return null;
+                }
+
+                ensureNext(pr, TOKEN_VAL_CLOS);
+
+                collection.add(value);
+
+                c = ignorablePageBreakAndWhiteSpace(pr);
+            }
+
+            if (c == TOKEN_VEC_CLOS) {
+                return collection;
+            } else if (c < 0) {
+                return null;
+            } else if (c != TOKEN_COMMA) {
+                return null;
+            }
+        }
+    }
+
+
+    private Object readSimple(int code, PushbackReader pr) throws IOException {
+        switch (code) {
+            case -1:
+                return null;
+
+            case TOKEN_SIMPLE_STRING:
+                return readQuoted(pr);
+
+            // Simple/Primitive, only use wrapper classes
+            case TOKEN_SIMPLE_INTEGER:
+            case TOKEN_PRIMITIVE_INT:
+                return Integer.valueOf(readQuoted(pr));
+
+            case TOKEN_SIMPLE_LONG:
+            case TOKEN_PRIMITIVE_LONG:
+                return Long.valueOf(readQuoted(pr));
+
+            case TOKEN_SIMPLE_FLOAT:
+            case TOKEN_PRIMITIVE_FLOAT:
+                int fBits = Integer.parseInt(readQuoted(pr));
+                return new Float(Float.intBitsToFloat(fBits));
+
+            case TOKEN_SIMPLE_DOUBLE:
+            case TOKEN_PRIMITIVE_DOUBLE:
+                long dBits = Long.parseLong(readQuoted(pr));
+                return new Double(Double.longBitsToDouble(dBits));
+
+            case TOKEN_SIMPLE_BYTE:
+            case TOKEN_PRIMITIVE_BYTE:
+                return Byte.valueOf(readQuoted(pr));
+
+            case TOKEN_SIMPLE_SHORT:
+            case TOKEN_PRIMITIVE_SHORT:
+                return Short.valueOf(readQuoted(pr));
+
+            case TOKEN_SIMPLE_CHARACTER:
+            case TOKEN_PRIMITIVE_CHAR:
+                String cString = readQuoted(pr);
+                if (cString != null && cString.length() > 0) {
+                    return new Character(cString.charAt(0));
+                }
+                return null;
+
+            case TOKEN_SIMPLE_BOOLEAN:
+            case TOKEN_PRIMITIVE_BOOLEAN:
+                return Boolean.valueOf(readQuoted(pr));
+
+            // unknown type code
+            default:
+                return null;
+        }
+    }
+
+
+    private void ensureNext(PushbackReader pr, int expected) throws IOException {
+        int next = read(pr);
+        if (next != expected) {
+            readFailure(next, expected);
+        }
+    }
+
+
+    private String readQuoted(PushbackReader pr) throws IOException {
+        StringBuffer buf = new StringBuffer();
+        for (; ; ) {
+            int c = read(pr);
+            switch (c) {
+                // escaped character
+                case '\\':
+                    c = read(pr);
+                    switch (c) {
+                        // well known escapes
+                        case 'b':
+                            buf.append('\b');
+                            break;
+                        case 't':
+                            buf.append('\t');
+                            break;
+                        case 'n':
+                            buf.append('\n');
+                            break;
+                        case 'f':
+                            buf.append('\f');
+                            break;
+                        case 'r':
+                            buf.append('\r');
+                            break;
+                        case 'u':// need 4 characters !
+                            char[] cbuf = new char[4];
+                            if (read(pr, cbuf) == 4) {
+                                c = Integer.parseInt(new String(cbuf), 16);
+                                buf.append((char) c);
+                            }
+                            break;
+
+                        // just an escaped character, unescape
+                        default:
+                            buf.append((char) c);
+                    }
+                    break;
+
+                // eof
+                case -1: // fall through
+
+                    // separator token
+                case TOKEN_EQ:
+                case TOKEN_VAL_CLOS:
+                    pr.unread(c);
+                    return buf.toString();
+
+                // no escaping
+                default:
+                    buf.append((char) c);
+            }
+        }
+    }
+
+    private int nextToken(PushbackReader pr, final boolean newLine) throws IOException {
+        int c = ignorableWhiteSpace(pr);
+
+        // immediately return EOF
+        if (c < 0) {
+            return (token = c);
+        }
+
+        // check for comment
+        if (newLine && c == TOKEN_COMMENT) {
+            // skip everything until end of line
+            do {
+                c = read(pr);
+            } while (c != -1 && c != '\n');
+            if (c == -1) {
+                return (token = c);
+            }
+            // and start over
+            return nextToken(pr, true);
+        }
+
+        // check whether there is a name
+        if (NAME_CHARS.get(c) || !TOKEN_CHARS.get(c)) {
+            // read the property name
+            pr.unread(c);
+            tokenValue = readQuoted(pr);
+            return (token = TOKEN_NAME);
+        }
+
+        // check another token
+        if (TOKEN_CHARS.get(c)) {
+            return (token = c);
+        }
+
+        // unexpected character -> so what ??
+        return (token = -1);
+    }
+
+
+    private int ignorableWhiteSpace(PushbackReader pr) throws IOException {
+        int c = read(pr);
+        while (c >= 0 && Character.isWhitespace((char) c)) {
+            c = read(pr);
+        }
+        return c;
+    }
+
+
+    private int ignorablePageBreakAndWhiteSpace(PushbackReader pr) throws IOException {
+        int c = ignorableWhiteSpace(pr);
+        for (; ; ) {
+            if (c != '\\') {
+                break;
+            }
+            int c1 = pr.read();
+            if (c1 == '\r' || c1 == '\n') {
+                c = ignorableWhiteSpace(pr);
+            } else {
+                pr.unread(c1);
+                break;
+            }
+        }
+        return c;
+    }
+
+
+    private int read(PushbackReader pr) throws IOException {
+        int c = pr.read();
+        if (c == '\r') {
+            int c1 = pr.read();
+            if (c1 != '\n') {
+                pr.unread(c1);
+            }
+            c = '\n';
+        }
+
+        if (c == '\n') {
+            line++;
+            pos = 0;
+        } else {
+            pos++;
+        }
+
+        return c;
+    }
+
+
+    private int read(PushbackReader pr, char[] buf) throws IOException {
+        for (int i = 0; i < buf.length; i++) {
+            int c = read(pr);
+            if (c >= 0) {
+                buf[i] = (char) c;
+            } else {
+                return i;
+            }
+        }
+
+        return buf.length;
+    }
+
+
+    private IOException readFailure(int current, int expected) {
+        return new IOException("Unexpected token " + current + "; expected: " + expected + " (line=" + line + ", pos="
+                + pos + ")");
+    }
+
+
+    // ---------- Configuration Output Implementation --------------------------
+
+    private static void writeValue(Writer out, Object value) throws IOException {
+        Class clazz = value.getClass();
+        if (clazz.isArray()) {
+            writeArray(out, value);
+        } else if (value instanceof Collection) {
+            writeCollection(out, (Collection) value);
+        } else {
+            writeType(out, clazz);
+            writeSimple(out, value);
+        }
+    }
+
+
+    private static void writeArray(Writer out, Object arrayValue) throws IOException {
+        int size = Array.getLength(arrayValue);
+        writeType(out, arrayValue.getClass().getComponentType());
+        out.write(TOKEN_ARR_OPEN);
+        out.write(COLLECTION_LINE_BREAK);
+        for (int i = 0; i < size; i++) {
+            writeCollectionElement(out, Array.get(arrayValue, i));
+        }
+        out.write(INDENT);
+        out.write(TOKEN_ARR_CLOS);
+    }
+
+
+    private static void writeCollection(Writer out, Collection collection) throws IOException {
+        if (collection.isEmpty()) {
+            out.write(TOKEN_VEC_OPEN);
+            out.write(COLLECTION_LINE_BREAK);
+            out.write(TOKEN_VEC_CLOS);
+        } else {
+            Iterator ci = collection.iterator();
+            Object firstElement = ci.next();
+
+            writeType(out, firstElement.getClass());
+            out.write(TOKEN_VEC_OPEN);
+            out.write(COLLECTION_LINE_BREAK);
+
+            writeCollectionElement(out, firstElement);
+
+            while (ci.hasNext()) {
+                writeCollectionElement(out, ci.next());
+            }
+            out.write(TOKEN_VEC_CLOS);
+        }
+    }
+
+
+    private static void writeCollectionElement(Writer out, Object element) throws IOException {
+        out.write(INDENT);
+        writeSimple(out, element);
+        out.write(TOKEN_COMMA);
+        out.write(COLLECTION_LINE_BREAK);
+    }
+
+
+    private static void writeType(Writer out, Class valueType) throws IOException {
+        Integer code = (Integer) TYPE_2_CODE.get(valueType);
+        if (code != null) {
+            out.write((char) code.intValue());
+        }
+    }
+
+
+    private static void writeSimple(Writer out, Object value) throws IOException {
+        if (value instanceof Double) {
+            double dVal = ((Double) value).doubleValue();
+            value = new Long(Double.doubleToRawLongBits(dVal));
+        } else if (value instanceof Float) {
+            float fVal = ((Float) value).floatValue();
+            value = new Integer(Float.floatToRawIntBits(fVal));
+        }
+
+        out.write(TOKEN_VAL_OPEN);
+        writeQuoted(out, String.valueOf(value));
+        out.write(TOKEN_VAL_CLOS);
+    }
+
+
+    private static void writeQuoted(Writer out, String simple) throws IOException {
+        if (simple == null || simple.length() == 0) {
+            return;
+        }
+
+        char c = 0;
+        int len = simple.length();
+        for (int i = 0; i < len; i++) {
+            c = simple.charAt(i);
+            switch (c) {
+                case '\\':
+                case TOKEN_VAL_CLOS:
+                case ' ':
+                case TOKEN_EQ:
+                    out.write('\\');
+                    out.write(c);
+                    break;
+
+                // well known escapes
+                case '\b':
+                    out.write("\\b");
+                    break;
+                case '\t':
+                    out.write("\\t");
+                    break;
+                case '\n':
+                    out.write("\\n");
+                    break;
+                case '\f':
+                    out.write("\\f");
+                    break;
+                case '\r':
+                    out.write("\\r");
+                    break;
+
+                // other escaping
+                default:
+                    if (c < ' ') {
+                        String t = "000" + Integer.toHexString(c);
+                        out.write("\\u" + t.substring(t.length() - 4));
+                    } else {
+                        out.write(c);
+                    }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9d10e254/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/base/TamayaPersistenceManager.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/base/TamayaPersistenceManager.java b/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/base/TamayaPersistenceManager.java
new file mode 100644
index 0000000..06deb9f
--- /dev/null
+++ b/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/base/TamayaPersistenceManager.java
@@ -0,0 +1,128 @@
+/*
+ * 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.osgi.base;
+
+import org.apache.felix.cm.PersistenceManager;
+import org.apache.felix.cm.file.FilePersistenceManager;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.functions.ConfigurationFunctions;
+import org.osgi.framework.BundleContext;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Implementation of the Felix {@link PersistenceManager}, which is used as a
+ * configuration backend for reading and writing configuration.
+ */
+class TamayaPersistenceManager implements PersistenceManager{
+
+    private FilePersistenceManager fallBackPM;
+    private BundleContext context;
+    private Map<String, Dictionary<String,String>> configs = new ConcurrentHashMap<>();
+
+    TamayaPersistenceManager(BundleContext bundleContext){
+        this.context = bundleContext;
+        fallBackPM = new FilePersistenceManager(context, bundleContext.getProperty("felix.cm.dir"));
+    }
+
+    @Override
+    public boolean exists(String pid) {
+        if(fallBackPM!=null && fallBackPM.exists(pid)){
+            return true;
+        }
+        return !ConfigurationProvider.getConfiguration().with(
+                ConfigurationFunctions.section(
+                        "__"+pid+"__"
+                )).getProperties().isEmpty();
+    }
+
+    @Override
+    public Dictionary load(String pid) throws IOException {
+        Dictionary dict = new Hashtable();
+        if(fallBackPM!=null){
+            try{
+                Dictionary loaded = fallBackPM.load(pid);
+                Enumeration<String> en = loaded.keys();
+                while(en.hasMoreElements()){
+                    String key = en.nextElement();
+                    dict.put(key, loaded.get(key));
+                }
+            } catch(IOException e){
+                if(!exists(pid)){
+                    throw new IOException("No such Config (neither in Tamaya, nor on the FW): " + pid, e);
+                }
+            }
+        }
+        Map<String,String> tamayaLoad = ConfigurationProvider.getConfiguration().with(
+                ConfigurationFunctions.section(
+                        "__"+pid+"__"
+                )).getProperties();
+        for(Map.Entry<String,String> en:tamayaLoad.entrySet()){
+            // TODO Make configurable, if Tamaya is overriding, or extending...
+            dict.put(en.getKey(), en.getValue());
+        }
+        configs.put(pid, dict);
+        return dict;
+    }
+
+    @Override
+    public Enumeration getDictionaries() throws IOException {
+        List<Dictionary> dicts = new ArrayList<>();
+        if(fallBackPM != null){
+            Enumeration en = fallBackPM.getDictionaries();
+            while(en.hasMoreElements()){
+                dicts.add((Dictionary)en.nextElement());
+            }
+        }
+        dicts.addAll(configs.values());
+        return Collections.enumeration(dicts);
+    }
+
+    @Override
+    public void store(String pid, Dictionary dictionary) throws IOException {
+        // TODO Define a configurable storage strategy
+        // 1: to file storage
+        // 2: to Tamaya
+        // 3: both
+        // 4: read only
+        if(fallBackPM != null){
+            fallBackPM.store(pid, dictionary);
+        }
+    }
+
+    @Override
+    public void delete(String pid) throws IOException {
+        // TODO Define a configurable storage strategy
+        // 1: to file storage
+        // 2: to Tamaya
+        // 3: both
+        // 4: read only
+        if(fallBackPM != null){
+            fallBackPM.delete(pid);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9d10e254/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/Activator.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/Activator.java b/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/Activator.java
deleted file mode 100644
index 9053aa7..0000000
--- a/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/Activator.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.integration.osgi.felix;
-
-import org.apache.felix.cm.PersistenceManager;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
-
-import java.util.Hashtable;
-
-/**
- * Activator that registers the Tamaya implementation of {@link org.apache.felix.cm.PersistenceManager},
- * hereby overriding the version registered by felix CM by default.
- */
-public class Activator implements BundleActivator{
-
-    /**
-     * Our registration, used on stop.
-     */
-    private ServiceRegistration<PersistenceManager> pmRegistration;
-
-
-    @Override
-    public void start(BundleContext bundleContext) throws Exception {
-        TamayaPersistenceManager tpm = new TamayaPersistenceManager(bundleContext);
-        Hashtable props = new Hashtable();
-        props.put( Constants.SERVICE_PID, tpm.getClass().getName() );
-        props.put( Constants.SERVICE_DESCRIPTION, "Apache Tamaya Persistence Manager" );
-        props.put( Constants.SERVICE_VENDOR, "Apache Software Foundation" );
-        Integer ranking = 10;
-        // TODO Make ranking configurable...
-        props.put( Constants.SERVICE_RANKING, ranking );
-        pmRegistration = bundleContext.registerService( PersistenceManager.class, tpm, props );
-    }
-
-    @Override
-    public void stop(BundleContext bundleContext) throws Exception {
-        if(pmRegistration!=null){
-            pmRegistration.unregister();
-            pmRegistration = null;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9d10e254/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/ConfigurationHandler.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/ConfigurationHandler.java b/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/ConfigurationHandler.java
deleted file mode 100644
index e020b3e..0000000
--- a/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/ConfigurationHandler.java
+++ /dev/null
@@ -1,757 +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.integration.osgi.felix;
-
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PushbackReader;
-import java.io.Writer;
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.BitSet;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-
-/**
- * The <code>ConfigurationHandler</code> class implements configuration reading
- * form a <code>java.io.InputStream</code> and writing to a
- * <code>java.io.OutputStream</code> on behalf of the
- * {@link FilePersistenceManager} class.
- * <p>
- * <pre>
- * cfg = prop &quot;=&quot; value .
- *  prop = symbolic-name . // 1.4.2 of OSGi Core Specification
- *  symbolic-name = token { &quot;.&quot; token } .
- *  token = { [ 0..9 ] | [ a..z ] | [ A..Z ] | '_' | '-' } .
- *  value = [ type ] ( &quot;[&quot; values &quot;]&quot; | &quot;(&quot; values &quot;)&quot; | simple ) .
- *  values = simple { &quot;,&quot; simple } .
- *  simple = &quot;&quot;&quot; stringsimple &quot;&quot;&quot; .
- *  type = // 1-char type code .
- *  stringsimple = // quoted string representation of the value .
- * </pre>
- */
-class ConfigurationHandler {
-    protected static final String ENCODING = "UTF-8";
-
-    protected static final int TOKEN_NAME = 'N';
-    protected static final int TOKEN_EQ = '=';
-    protected static final int TOKEN_ARR_OPEN = '[';
-    protected static final int TOKEN_ARR_CLOS = ']';
-    protected static final int TOKEN_VEC_OPEN = '(';
-    protected static final int TOKEN_VEC_CLOS = ')';
-    protected static final int TOKEN_COMMA = ',';
-    protected static final int TOKEN_VAL_OPEN = '"'; // '{';
-    protected static final int TOKEN_VAL_CLOS = '"'; // '}';
-
-    protected static final int TOKEN_COMMENT = '#';
-
-    // simple types (string & primitive wrappers)
-    protected static final int TOKEN_SIMPLE_STRING = 'T';
-    protected static final int TOKEN_SIMPLE_INTEGER = 'I';
-    protected static final int TOKEN_SIMPLE_LONG = 'L';
-    protected static final int TOKEN_SIMPLE_FLOAT = 'F';
-    protected static final int TOKEN_SIMPLE_DOUBLE = 'D';
-    protected static final int TOKEN_SIMPLE_BYTE = 'X';
-    protected static final int TOKEN_SIMPLE_SHORT = 'S';
-    protected static final int TOKEN_SIMPLE_CHARACTER = 'C';
-    protected static final int TOKEN_SIMPLE_BOOLEAN = 'B';
-
-    // primitives
-    protected static final int TOKEN_PRIMITIVE_INT = 'i';
-    protected static final int TOKEN_PRIMITIVE_LONG = 'l';
-    protected static final int TOKEN_PRIMITIVE_FLOAT = 'f';
-    protected static final int TOKEN_PRIMITIVE_DOUBLE = 'd';
-    protected static final int TOKEN_PRIMITIVE_BYTE = 'x';
-    protected static final int TOKEN_PRIMITIVE_SHORT = 's';
-    protected static final int TOKEN_PRIMITIVE_CHAR = 'c';
-    protected static final int TOKEN_PRIMITIVE_BOOLEAN = 'b';
-
-    protected static final String CRLF = "\r\n";
-    protected static final String INDENT = "  ";
-    protected static final String COLLECTION_LINE_BREAK = " \\\r\n";
-
-    protected static final Map CODE_2_TYPE;
-    protected static final Map TYPE_2_CODE;
-
-    // set of valid characters for "symblic-name"
-    private static final BitSet NAME_CHARS;
-    private static final BitSet TOKEN_CHARS;
-
-    static {
-        TYPE_2_CODE = new HashMap();
-
-        // simple (exclusive String whose type code is not written)
-        TYPE_2_CODE.put(Integer.class, new Integer(TOKEN_SIMPLE_INTEGER));
-        TYPE_2_CODE.put(Long.class, new Integer(TOKEN_SIMPLE_LONG));
-        TYPE_2_CODE.put(Float.class, new Integer(TOKEN_SIMPLE_FLOAT));
-        TYPE_2_CODE.put(Double.class, new Integer(TOKEN_SIMPLE_DOUBLE));
-        TYPE_2_CODE.put(Byte.class, new Integer(TOKEN_SIMPLE_BYTE));
-        TYPE_2_CODE.put(Short.class, new Integer(TOKEN_SIMPLE_SHORT));
-        TYPE_2_CODE.put(Character.class, new Integer(TOKEN_SIMPLE_CHARACTER));
-        TYPE_2_CODE.put(Boolean.class, new Integer(TOKEN_SIMPLE_BOOLEAN));
-
-        // primitives
-        TYPE_2_CODE.put(Integer.TYPE, new Integer(TOKEN_PRIMITIVE_INT));
-        TYPE_2_CODE.put(Long.TYPE, new Integer(TOKEN_PRIMITIVE_LONG));
-        TYPE_2_CODE.put(Float.TYPE, new Integer(TOKEN_PRIMITIVE_FLOAT));
-        TYPE_2_CODE.put(Double.TYPE, new Integer(TOKEN_PRIMITIVE_DOUBLE));
-        TYPE_2_CODE.put(Byte.TYPE, new Integer(TOKEN_PRIMITIVE_BYTE));
-        TYPE_2_CODE.put(Short.TYPE, new Integer(TOKEN_PRIMITIVE_SHORT));
-        TYPE_2_CODE.put(Character.TYPE, new Integer(TOKEN_PRIMITIVE_CHAR));
-        TYPE_2_CODE.put(Boolean.TYPE, new Integer(TOKEN_PRIMITIVE_BOOLEAN));
-
-        // reverse map to map type codes to classes, string class mapping
-        // to be added manually, as the string type code is not written and
-        // hence not included in the TYPE_2_CODE map
-        CODE_2_TYPE = new HashMap();
-        for (Iterator ti = TYPE_2_CODE.entrySet().iterator(); ti.hasNext(); ) {
-            Map.Entry entry = (Map.Entry) ti.next();
-            CODE_2_TYPE.put(entry.getValue(), entry.getKey());
-        }
-        CODE_2_TYPE.put(new Integer(TOKEN_SIMPLE_STRING), String.class);
-
-        NAME_CHARS = new BitSet();
-        for (int i = '0'; i <= '9'; i++) {
-            NAME_CHARS.set(i);
-        }
-        for (int i = 'a'; i <= 'z'; i++) {
-            NAME_CHARS.set(i);
-        }
-        for (int i = 'A'; i <= 'Z'; i++) {
-            NAME_CHARS.set(i);
-        }
-        NAME_CHARS.set('_');
-        NAME_CHARS.set('-');
-        NAME_CHARS.set('.');
-        NAME_CHARS.set('\\');
-
-        TOKEN_CHARS = new BitSet();
-        TOKEN_CHARS.set(TOKEN_EQ);
-        TOKEN_CHARS.set(TOKEN_ARR_OPEN);
-        TOKEN_CHARS.set(TOKEN_ARR_CLOS);
-        TOKEN_CHARS.set(TOKEN_VEC_OPEN);
-        TOKEN_CHARS.set(TOKEN_VEC_CLOS);
-        TOKEN_CHARS.set(TOKEN_COMMA);
-        TOKEN_CHARS.set(TOKEN_VAL_OPEN);
-        TOKEN_CHARS.set(TOKEN_VAL_CLOS);
-        TOKEN_CHARS.set(TOKEN_SIMPLE_STRING);
-        TOKEN_CHARS.set(TOKEN_SIMPLE_INTEGER);
-        TOKEN_CHARS.set(TOKEN_SIMPLE_LONG);
-        TOKEN_CHARS.set(TOKEN_SIMPLE_FLOAT);
-        TOKEN_CHARS.set(TOKEN_SIMPLE_DOUBLE);
-        TOKEN_CHARS.set(TOKEN_SIMPLE_BYTE);
-        TOKEN_CHARS.set(TOKEN_SIMPLE_SHORT);
-        TOKEN_CHARS.set(TOKEN_SIMPLE_CHARACTER);
-        TOKEN_CHARS.set(TOKEN_SIMPLE_BOOLEAN);
-
-        // primitives
-        TOKEN_CHARS.set(TOKEN_PRIMITIVE_INT);
-        TOKEN_CHARS.set(TOKEN_PRIMITIVE_LONG);
-        TOKEN_CHARS.set(TOKEN_PRIMITIVE_FLOAT);
-        TOKEN_CHARS.set(TOKEN_PRIMITIVE_DOUBLE);
-        TOKEN_CHARS.set(TOKEN_PRIMITIVE_BYTE);
-        TOKEN_CHARS.set(TOKEN_PRIMITIVE_SHORT);
-        TOKEN_CHARS.set(TOKEN_PRIMITIVE_CHAR);
-        TOKEN_CHARS.set(TOKEN_PRIMITIVE_BOOLEAN);
-    }
-
-
-    /**
-     * Writes the configuration data from the <code>Dictionary</code> to the
-     * given <code>OutputStream</code>.
-     * <p>
-     * This method writes at the current location in the stream and does not
-     * close the outputstream.
-     *
-     * @param out        The <code>OutputStream</code> to write the configurtion data
-     *                   to.
-     * @param properties The <code>Dictionary</code> to write.
-     * @throws IOException If an error occurrs writing to the output stream.
-     */
-    public static void write(OutputStream out, Dictionary properties) throws IOException {
-        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out, ENCODING));
-
-        for (Enumeration ce = orderedKeys(properties); ce.hasMoreElements(); ) {
-            String key = (String) ce.nextElement();
-
-            // cfg = prop "=" value "." .
-            writeQuoted(bw, key);
-            bw.write(TOKEN_EQ);
-            writeValue(bw, properties.get(key));
-            bw.write(CRLF);
-        }
-
-        bw.flush();
-    }
-
-    /**
-     * Generates an <code>Enumeration</code> for the given
-     * <code>Dictionary</code> where the keys of the <code>Dictionary</code>
-     * are provided in sorted order.
-     *
-     * @param properties The <code>Dictionary</code> that keys are sorted.
-     * @return An <code>Enumeration</code> that provides the keys of
-     * properties in an ordered manner.
-     */
-    private static Enumeration orderedKeys(Dictionary properties) {
-        String[] keyArray = new String[properties.size()];
-        int i = 0;
-        for (Enumeration ce = properties.keys(); ce.hasMoreElements(); ) {
-            keyArray[i] = (String) ce.nextElement();
-            i++;
-        }
-        Arrays.sort(keyArray);
-        return Collections.enumeration(Arrays.asList(keyArray));
-    }
-
-
-    /**
-     * Reads configuration data from the given <code>InputStream</code> and
-     * returns a new <code>Dictionary</code> object containing the data.
-     * <p>
-     * This method reads from the current location in the stream upto the end of
-     * the stream but does not close the stream at the end.
-     *
-     * @param ins The <code>InputStream</code> from which to read the
-     *            configuration data.
-     * @return A <code>Dictionary</code> object containing the configuration
-     * data. This object may be empty if the stream contains no
-     * configuration data.
-     * @throws IOException If an error occurrs reading from the stream. This exception
-     *                     is also thrown if a syntax error is encountered.
-     */
-    public static Dictionary read(InputStream ins) throws IOException {
-        return new ConfigurationHandler().readInternal(ins);
-    }
-
-
-    // private constructor, this class is not to be instantiated from the
-    // outside
-    private ConfigurationHandler() {
-    }
-
-    // ---------- Configuration Input Implementation ---------------------------
-
-    private int token;
-    private String tokenValue;
-    private int line;
-    private int pos;
-
-
-    private Dictionary readInternal(InputStream ins) throws IOException {
-        BufferedReader br = new BufferedReader(new InputStreamReader(ins, ENCODING));
-        PushbackReader pr = new PushbackReader(br, 1);
-
-        token = 0;
-        tokenValue = null;
-        line = 0;
-        pos = 0;
-
-        Hashtable configuration = new Hashtable();
-        token = 0;
-        while (nextToken(pr, true) == TOKEN_NAME) {
-            String key = tokenValue;
-
-            // expect equal sign
-            if (nextToken(pr, false) != TOKEN_EQ) {
-                throw readFailure(token, TOKEN_EQ);
-            }
-
-            // expect the token value
-            Object value = readValue(pr);
-            if (value != null) {
-                configuration.put(key, value);
-            }
-        }
-
-        return configuration;
-    }
-
-
-    /**
-     * value = type ( "[" values "]" | "(" values ")" | simple ) . values =
-     * value { "," value } . simple = "{" stringsimple "}" . type = // 1-char
-     * type code . stringsimple = // quoted string representation of the value .
-     *
-     * @param pr
-     * @return
-     * @throws IOException
-     */
-    private Object readValue(PushbackReader pr) throws IOException {
-        // read (optional) type code
-        int type = read(pr);
-
-        // read value kind code if type code is not a value kinde code
-        int code;
-        if (CODE_2_TYPE.containsKey(new Integer(type))) {
-            code = read(pr);
-        } else {
-            code = type;
-            type = TOKEN_SIMPLE_STRING;
-        }
-
-        switch (code) {
-            case TOKEN_ARR_OPEN:
-                return readArray(type, pr);
-
-            case TOKEN_VEC_OPEN:
-                return readCollection(type, pr);
-
-            case TOKEN_VAL_OPEN:
-                Object value = readSimple(type, pr);
-                ensureNext(pr, TOKEN_VAL_CLOS);
-                return value;
-
-            default:
-                return null;
-        }
-    }
-
-
-    private Object readArray(int typeCode, PushbackReader pr) throws IOException {
-        List list = new ArrayList();
-        for (; ; ) {
-            int c = ignorablePageBreakAndWhiteSpace(pr);
-            if (c == TOKEN_VAL_OPEN) {
-                Object value = readSimple(typeCode, pr);
-                if (value == null) {
-                    // abort due to error
-                    return null;
-                }
-
-                ensureNext(pr, TOKEN_VAL_CLOS);
-
-                list.add(value);
-
-                c = ignorablePageBreakAndWhiteSpace(pr);
-            }
-
-            if (c == TOKEN_ARR_CLOS) {
-                Class type = (Class) CODE_2_TYPE.get(new Integer(typeCode));
-                Object array = Array.newInstance(type, list.size());
-                for (int i = 0; i < list.size(); i++) {
-                    Array.set(array, i, list.get(i));
-                }
-                return array;
-            } else if (c < 0) {
-                return null;
-            } else if (c != TOKEN_COMMA) {
-                return null;
-            }
-        }
-    }
-
-
-    private Collection readCollection(int typeCode, PushbackReader pr) throws IOException {
-        Collection collection = new ArrayList();
-        for (; ; ) {
-            int c = ignorablePageBreakAndWhiteSpace(pr);
-            if (c == TOKEN_VAL_OPEN) {
-                Object value = readSimple(typeCode, pr);
-                if (value == null) {
-                    // abort due to error
-                    return null;
-                }
-
-                ensureNext(pr, TOKEN_VAL_CLOS);
-
-                collection.add(value);
-
-                c = ignorablePageBreakAndWhiteSpace(pr);
-            }
-
-            if (c == TOKEN_VEC_CLOS) {
-                return collection;
-            } else if (c < 0) {
-                return null;
-            } else if (c != TOKEN_COMMA) {
-                return null;
-            }
-        }
-    }
-
-
-    private Object readSimple(int code, PushbackReader pr) throws IOException {
-        switch (code) {
-            case -1:
-                return null;
-
-            case TOKEN_SIMPLE_STRING:
-                return readQuoted(pr);
-
-            // Simple/Primitive, only use wrapper classes
-            case TOKEN_SIMPLE_INTEGER:
-            case TOKEN_PRIMITIVE_INT:
-                return Integer.valueOf(readQuoted(pr));
-
-            case TOKEN_SIMPLE_LONG:
-            case TOKEN_PRIMITIVE_LONG:
-                return Long.valueOf(readQuoted(pr));
-
-            case TOKEN_SIMPLE_FLOAT:
-            case TOKEN_PRIMITIVE_FLOAT:
-                int fBits = Integer.parseInt(readQuoted(pr));
-                return new Float(Float.intBitsToFloat(fBits));
-
-            case TOKEN_SIMPLE_DOUBLE:
-            case TOKEN_PRIMITIVE_DOUBLE:
-                long dBits = Long.parseLong(readQuoted(pr));
-                return new Double(Double.longBitsToDouble(dBits));
-
-            case TOKEN_SIMPLE_BYTE:
-            case TOKEN_PRIMITIVE_BYTE:
-                return Byte.valueOf(readQuoted(pr));
-
-            case TOKEN_SIMPLE_SHORT:
-            case TOKEN_PRIMITIVE_SHORT:
-                return Short.valueOf(readQuoted(pr));
-
-            case TOKEN_SIMPLE_CHARACTER:
-            case TOKEN_PRIMITIVE_CHAR:
-                String cString = readQuoted(pr);
-                if (cString != null && cString.length() > 0) {
-                    return new Character(cString.charAt(0));
-                }
-                return null;
-
-            case TOKEN_SIMPLE_BOOLEAN:
-            case TOKEN_PRIMITIVE_BOOLEAN:
-                return Boolean.valueOf(readQuoted(pr));
-
-            // unknown type code
-            default:
-                return null;
-        }
-    }
-
-
-    private void ensureNext(PushbackReader pr, int expected) throws IOException {
-        int next = read(pr);
-        if (next != expected) {
-            readFailure(next, expected);
-        }
-    }
-
-
-    private String readQuoted(PushbackReader pr) throws IOException {
-        StringBuffer buf = new StringBuffer();
-        for (; ; ) {
-            int c = read(pr);
-            switch (c) {
-                // escaped character
-                case '\\':
-                    c = read(pr);
-                    switch (c) {
-                        // well known escapes
-                        case 'b':
-                            buf.append('\b');
-                            break;
-                        case 't':
-                            buf.append('\t');
-                            break;
-                        case 'n':
-                            buf.append('\n');
-                            break;
-                        case 'f':
-                            buf.append('\f');
-                            break;
-                        case 'r':
-                            buf.append('\r');
-                            break;
-                        case 'u':// need 4 characters !
-                            char[] cbuf = new char[4];
-                            if (read(pr, cbuf) == 4) {
-                                c = Integer.parseInt(new String(cbuf), 16);
-                                buf.append((char) c);
-                            }
-                            break;
-
-                        // just an escaped character, unescape
-                        default:
-                            buf.append((char) c);
-                    }
-                    break;
-
-                // eof
-                case -1: // fall through
-
-                    // separator token
-                case TOKEN_EQ:
-                case TOKEN_VAL_CLOS:
-                    pr.unread(c);
-                    return buf.toString();
-
-                // no escaping
-                default:
-                    buf.append((char) c);
-            }
-        }
-    }
-
-    private int nextToken(PushbackReader pr, final boolean newLine) throws IOException {
-        int c = ignorableWhiteSpace(pr);
-
-        // immediately return EOF
-        if (c < 0) {
-            return (token = c);
-        }
-
-        // check for comment
-        if (newLine && c == TOKEN_COMMENT) {
-            // skip everything until end of line
-            do {
-                c = read(pr);
-            } while (c != -1 && c != '\n');
-            if (c == -1) {
-                return (token = c);
-            }
-            // and start over
-            return nextToken(pr, true);
-        }
-
-        // check whether there is a name
-        if (NAME_CHARS.get(c) || !TOKEN_CHARS.get(c)) {
-            // read the property name
-            pr.unread(c);
-            tokenValue = readQuoted(pr);
-            return (token = TOKEN_NAME);
-        }
-
-        // check another token
-        if (TOKEN_CHARS.get(c)) {
-            return (token = c);
-        }
-
-        // unexpected character -> so what ??
-        return (token = -1);
-    }
-
-
-    private int ignorableWhiteSpace(PushbackReader pr) throws IOException {
-        int c = read(pr);
-        while (c >= 0 && Character.isWhitespace((char) c)) {
-            c = read(pr);
-        }
-        return c;
-    }
-
-
-    private int ignorablePageBreakAndWhiteSpace(PushbackReader pr) throws IOException {
-        int c = ignorableWhiteSpace(pr);
-        for (; ; ) {
-            if (c != '\\') {
-                break;
-            }
-            int c1 = pr.read();
-            if (c1 == '\r' || c1 == '\n') {
-                c = ignorableWhiteSpace(pr);
-            } else {
-                pr.unread(c1);
-                break;
-            }
-        }
-        return c;
-    }
-
-
-    private int read(PushbackReader pr) throws IOException {
-        int c = pr.read();
-        if (c == '\r') {
-            int c1 = pr.read();
-            if (c1 != '\n') {
-                pr.unread(c1);
-            }
-            c = '\n';
-        }
-
-        if (c == '\n') {
-            line++;
-            pos = 0;
-        } else {
-            pos++;
-        }
-
-        return c;
-    }
-
-
-    private int read(PushbackReader pr, char[] buf) throws IOException {
-        for (int i = 0; i < buf.length; i++) {
-            int c = read(pr);
-            if (c >= 0) {
-                buf[i] = (char) c;
-            } else {
-                return i;
-            }
-        }
-
-        return buf.length;
-    }
-
-
-    private IOException readFailure(int current, int expected) {
-        return new IOException("Unexpected token " + current + "; expected: " + expected + " (line=" + line + ", pos="
-                + pos + ")");
-    }
-
-
-    // ---------- Configuration Output Implementation --------------------------
-
-    private static void writeValue(Writer out, Object value) throws IOException {
-        Class clazz = value.getClass();
-        if (clazz.isArray()) {
-            writeArray(out, value);
-        } else if (value instanceof Collection) {
-            writeCollection(out, (Collection) value);
-        } else {
-            writeType(out, clazz);
-            writeSimple(out, value);
-        }
-    }
-
-
-    private static void writeArray(Writer out, Object arrayValue) throws IOException {
-        int size = Array.getLength(arrayValue);
-        writeType(out, arrayValue.getClass().getComponentType());
-        out.write(TOKEN_ARR_OPEN);
-        out.write(COLLECTION_LINE_BREAK);
-        for (int i = 0; i < size; i++) {
-            writeCollectionElement(out, Array.get(arrayValue, i));
-        }
-        out.write(INDENT);
-        out.write(TOKEN_ARR_CLOS);
-    }
-
-
-    private static void writeCollection(Writer out, Collection collection) throws IOException {
-        if (collection.isEmpty()) {
-            out.write(TOKEN_VEC_OPEN);
-            out.write(COLLECTION_LINE_BREAK);
-            out.write(TOKEN_VEC_CLOS);
-        } else {
-            Iterator ci = collection.iterator();
-            Object firstElement = ci.next();
-
-            writeType(out, firstElement.getClass());
-            out.write(TOKEN_VEC_OPEN);
-            out.write(COLLECTION_LINE_BREAK);
-
-            writeCollectionElement(out, firstElement);
-
-            while (ci.hasNext()) {
-                writeCollectionElement(out, ci.next());
-            }
-            out.write(TOKEN_VEC_CLOS);
-        }
-    }
-
-
-    private static void writeCollectionElement(Writer out, Object element) throws IOException {
-        out.write(INDENT);
-        writeSimple(out, element);
-        out.write(TOKEN_COMMA);
-        out.write(COLLECTION_LINE_BREAK);
-    }
-
-
-    private static void writeType(Writer out, Class valueType) throws IOException {
-        Integer code = (Integer) TYPE_2_CODE.get(valueType);
-        if (code != null) {
-            out.write((char) code.intValue());
-        }
-    }
-
-
-    private static void writeSimple(Writer out, Object value) throws IOException {
-        if (value instanceof Double) {
-            double dVal = ((Double) value).doubleValue();
-            value = new Long(Double.doubleToRawLongBits(dVal));
-        } else if (value instanceof Float) {
-            float fVal = ((Float) value).floatValue();
-            value = new Integer(Float.floatToRawIntBits(fVal));
-        }
-
-        out.write(TOKEN_VAL_OPEN);
-        writeQuoted(out, String.valueOf(value));
-        out.write(TOKEN_VAL_CLOS);
-    }
-
-
-    private static void writeQuoted(Writer out, String simple) throws IOException {
-        if (simple == null || simple.length() == 0) {
-            return;
-        }
-
-        char c = 0;
-        int len = simple.length();
-        for (int i = 0; i < len; i++) {
-            c = simple.charAt(i);
-            switch (c) {
-                case '\\':
-                case TOKEN_VAL_CLOS:
-                case ' ':
-                case TOKEN_EQ:
-                    out.write('\\');
-                    out.write(c);
-                    break;
-
-                // well known escapes
-                case '\b':
-                    out.write("\\b");
-                    break;
-                case '\t':
-                    out.write("\\t");
-                    break;
-                case '\n':
-                    out.write("\\n");
-                    break;
-                case '\f':
-                    out.write("\\f");
-                    break;
-                case '\r':
-                    out.write("\\r");
-                    break;
-
-                // other escaping
-                default:
-                    if (c < ' ') {
-                        String t = "000" + Integer.toHexString(c);
-                        out.write("\\u" + t.substring(t.length() - 4));
-                    } else {
-                        out.write(c);
-                    }
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9d10e254/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/TamayaPersistenceManager.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/TamayaPersistenceManager.java b/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/TamayaPersistenceManager.java
deleted file mode 100644
index 7f94f7f..0000000
--- a/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/TamayaPersistenceManager.java
+++ /dev/null
@@ -1,128 +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.integration.osgi.felix;
-
-import org.apache.felix.cm.PersistenceManager;
-import org.apache.felix.cm.file.FilePersistenceManager;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.functions.ConfigurationFunctions;
-import org.osgi.framework.BundleContext;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Implementation of the Felix {@link PersistenceManager}, which is used as a
- * configuration backend for reading and writing configuration.
- */
-class TamayaPersistenceManager implements PersistenceManager{
-
-    private FilePersistenceManager fallBackPM;
-    private BundleContext context;
-    private Map<String, Dictionary<String,String>> configs = new ConcurrentHashMap<>();
-
-    TamayaPersistenceManager(BundleContext bundleContext){
-        this.context = bundleContext;
-        fallBackPM = new FilePersistenceManager(context, bundleContext.getProperty("felix.cm.dir"));
-    }
-
-    @Override
-    public boolean exists(String pid) {
-        if(fallBackPM!=null && fallBackPM.exists(pid)){
-            return true;
-        }
-        return !ConfigurationProvider.getConfiguration().with(
-                ConfigurationFunctions.section(
-                        "__"+pid+"__"
-                )).getProperties().isEmpty();
-    }
-
-    @Override
-    public Dictionary load(String pid) throws IOException {
-        Dictionary dict = new Hashtable();
-        if(fallBackPM!=null){
-            try{
-                Dictionary loaded = fallBackPM.load(pid);
-                Enumeration<String> en = loaded.keys();
-                while(en.hasMoreElements()){
-                    String key = en.nextElement();
-                    dict.put(key, loaded.get(key));
-                }
-            } catch(IOException e){
-                if(!exists(pid)){
-                    throw new IOException("No such Config (neither in Tamaya, nor on the FW): " + pid, e);
-                }
-            }
-        }
-        Map<String,String> tamayaLoad = ConfigurationProvider.getConfiguration().with(
-                ConfigurationFunctions.section(
-                        "__"+pid+"__"
-                )).getProperties();
-        for(Map.Entry<String,String> en:tamayaLoad.entrySet()){
-            // TODO Make configurable, if Tamaya is overriding, or extending...
-            dict.put(en.getKey(), en.getValue());
-        }
-        configs.put(pid, dict);
-        return dict;
-    }
-
-    @Override
-    public Enumeration getDictionaries() throws IOException {
-        List<Dictionary> dicts = new ArrayList<>();
-        if(fallBackPM != null){
-            Enumeration en = fallBackPM.getDictionaries();
-            while(en.hasMoreElements()){
-                dicts.add((Dictionary)en.nextElement());
-            }
-        }
-        dicts.addAll(configs.values());
-        return Collections.enumeration(dicts);
-    }
-
-    @Override
-    public void store(String pid, Dictionary dictionary) throws IOException {
-        // TODO Define a configurable storage strategy
-        // 1: to file storage
-        // 2: to Tamaya
-        // 3: both
-        // 4: read only
-        if(fallBackPM != null){
-            fallBackPM.store(pid, dictionary);
-        }
-    }
-
-    @Override
-    public void delete(String pid) throws IOException {
-        // TODO Define a configurable storage strategy
-        // 1: to file storage
-        // 2: to Tamaya
-        // 3: both
-        // 4: read only
-        if(fallBackPM != null){
-            fallBackPM.delete(pid);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9d10e254/modules/integration/osgi/felix/src/test/java/org/apache/tamaya/integration/osgi/base/TestConfigIntegration.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/test/java/org/apache/tamaya/integration/osgi/base/TestConfigIntegration.java b/modules/integration/osgi/felix/src/test/java/org/apache/tamaya/integration/osgi/base/TestConfigIntegration.java
new file mode 100644
index 0000000..1ebc54d
--- /dev/null
+++ b/modules/integration/osgi/felix/src/test/java/org/apache/tamaya/integration/osgi/base/TestConfigIntegration.java
@@ -0,0 +1,173 @@
+/*
+ * 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.osgi.base;
+
+import org.apache.felix.cm.PersistenceManager;
+import org.apache.tamaya.ConfigurationProvider;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.osgi.metadata.OSGiManifestBuilder;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.Asset;
+import org.jboss.shrinkwrap.api.importer.ZipImporter;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.resolver.api.maven.Maven;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Dictionary;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(Arquillian.class)
+public class TestConfigIntegration{
+
+    private static final String TAMAYA_VERSION = "0.2-incubating-SNAPSHOT";
+
+    @ArquillianResource BundleContext context;
+
+    //////////////////////////////////////////////////////// Test setup //////////////////////////////////
+
+    @Deployment
+    public static JavaArchive createdeployment() {
+        final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "tamaya-config.jar");
+        archive.setManifest(new Asset() {
+            public InputStream openStream() {
+                OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
+                builder.addBundleSymbolicName(archive.getName());
+                builder.addBundleManifestVersion(2);
+                builder.addImportPackages("org.junit", "org.apache.felix.cm.file", "org.apache.tamaya.integration.osgi.felix");
+                builder.addImportPackages(PersistenceManager.class, ConfigurationAdmin.class, ConfigurationProvider.class);
+                builder.addBundleActivator(Activator.class);
+                return builder.openStream();
+            }
+        });
+        archive.addClasses(Activator.class, ConfigurationHandler.class, TamayaPersistenceManager.class);
+//        archive.addAsResource("META-INF/javaconfiguration.properties");
+        return archive;
+    }
+
+    @Deployment(name="felix.main")
+    public static JavaArchive deployMain() {
+        return ShrinkWrap.create(ZipImporter.class, "felix.main-5.4.0.jar")
+                .importFrom(new File("src/container/org.apache.felix.main-5.4.0.jar"))
+                .as(JavaArchive.class);
+    }
+
+    @Deployment(name="ConfigAdmin")
+    public static JavaArchive deployConfigAdmin() {
+        return ShrinkWrap.create(ZipImporter.class, "configadmin-1.8.8.jar")
+                .importFrom(new File("src/container/org.apache.felix.configadmin-1.8.8.jar"))
+                .as(JavaArchive.class);
+    }
+
+    @Deployment(name="tamaya-api")
+    public static JavaArchive deployTamayaAPI() {
+        return ShrinkWrap.create(ZipImporter.class, "tamaya-api.jar")
+                .importFrom(getBundleFile("tamaya-api:"+TAMAYA_VERSION))
+                .as(JavaArchive.class);
+    }
+
+    @Deployment(name="tamaya-core")
+    public static JavaArchive deployTamayaCore() {
+        return ShrinkWrap.create(ZipImporter.class, "tamaya-core.jar")
+                .importFrom(getBundleFile("tamaya-core:"+TAMAYA_VERSION))
+                .as(JavaArchive.class);
+    }
+
+    @Deployment(name="javax.annotation")
+    public static JavaArchive deployJavaxAnnotation() {
+        return ShrinkWrap.create(ZipImporter.class, "javax.annotation.jar")
+                .importFrom(Maven.configureResolver()
+                        .withMavenCentralRepo(false)
+                        .withClassPathResolution(true)
+                        .resolve("org.apache.geronimo.specs:geronimo-annotation_1.2_spec:1.0-alpha-1")
+                        .withoutTransitivity().asSingleFile())
+                .as(JavaArchive.class);
+    }
+
+    private static File getBundleFile(String artifactId) {
+        // Check
+        return Maven.configureResolver()
+                .withMavenCentralRepo(false)
+                .withClassPathResolution(true)
+                .resolve("org.apache.tamaya:" + artifactId).withoutTransitivity().asSingleFile();
+    }
+
+
+    //////////////////////////////////////////////////////// Tests //////////////////////////////////
+
+
+    @Before
+    public void startBundles(){
+//        for(Bundle bundle:context.getBundles()){
+//            context
+//                bundle.start();
+        try{
+            context.getBundle(0).start();
+        } catch (BundleException e) {
+            e.printStackTrace();
+        }
+//        }
+    }
+
+    @Test @Ignore
+    public void testTamayaPersistenceManagerAvailable(@ArquillianResource Bundle bundle) throws Exception {
+        ServiceReference<PersistenceManager> configRef = context.getServiceReference(PersistenceManager.class);
+        // TODO continue here...
+        assertNotNull(configRef);
+        PersistenceManager pm = context.getService(configRef);
+        assertNotNull(pm);
+        Dictionary tamayaConf = pm.load("tamaya-test");
+        assertNotNull(tamayaConf);
+        assertEquals("success!", tamayaConf.get("tamaya-test-property"));
+    }
+
+    @Test @Ignore
+    public void testTamayaConfigAvailableOnConfig() throws Exception {
+        ServiceReference<ConfigurationAdmin> configRef = context.getServiceReference(ConfigurationAdmin.class);
+        assertNotNull(configRef);
+        ConfigurationAdmin configAdmin = (ConfigurationAdmin)context.getService(configRef);
+        assertNotNull(configRef);
+        Configuration tamayaConf = configAdmin.getConfiguration("tamaya-test");
+        assertNotNull(tamayaConf);
+        assertEquals("success!", tamayaConf.getProperties().get("tamaya-test-property"));
+    }
+
+    @Test
+    public void testBundleContextInjection() throws Exception {
+        assertNotNull("BundleContext injected", context);
+        System.err.println(Arrays.toString(context.getBundles()));
+        assertEquals("System Bundle ID", 0, context.getBundle().getBundleId());
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9d10e254/modules/integration/osgi/felix/src/test/java/org/apache/tamaya/integration/osgi/felix/TestConfigIntegration.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/test/java/org/apache/tamaya/integration/osgi/felix/TestConfigIntegration.java b/modules/integration/osgi/felix/src/test/java/org/apache/tamaya/integration/osgi/felix/TestConfigIntegration.java
deleted file mode 100644
index 237e0c5..0000000
--- a/modules/integration/osgi/felix/src/test/java/org/apache/tamaya/integration/osgi/felix/TestConfigIntegration.java
+++ /dev/null
@@ -1,173 +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.integration.osgi.felix;
-
-import org.apache.felix.cm.PersistenceManager;
-import org.apache.tamaya.ConfigurationProvider;
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.test.api.ArquillianResource;
-import org.jboss.osgi.metadata.OSGiManifestBuilder;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.Asset;
-import org.jboss.shrinkwrap.api.importer.ZipImporter;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.Maven;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-
-import java.io.File;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.Dictionary;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-@RunWith(Arquillian.class)
-public class TestConfigIntegration{
-
-    private static final String TAMAYA_VERSION = "0.2-incubating-SNAPSHOT";
-
-    @ArquillianResource BundleContext context;
-
-    //////////////////////////////////////////////////////// Test setup //////////////////////////////////
-
-    @Deployment
-    public static JavaArchive createdeployment() {
-        final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "tamaya-config.jar");
-        archive.setManifest(new Asset() {
-            public InputStream openStream() {
-                OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
-                builder.addBundleSymbolicName(archive.getName());
-                builder.addBundleManifestVersion(2);
-                builder.addImportPackages("org.junit", "org.apache.felix.cm.file", "org.apache.tamaya.integration.osgi.felix");
-                builder.addImportPackages(PersistenceManager.class, ConfigurationAdmin.class, ConfigurationProvider.class);
-                builder.addBundleActivator(Activator.class);
-                return builder.openStream();
-            }
-        });
-        archive.addClasses(Activator.class, ConfigurationHandler.class, TamayaPersistenceManager.class);
-//        archive.addAsResource("META-INF/javaconfiguration.properties");
-        return archive;
-    }
-
-    @Deployment(name="felix.main")
-    public static JavaArchive deployMain() {
-        return ShrinkWrap.create(ZipImporter.class, "felix.main-5.4.0.jar")
-                .importFrom(new File("src/container/org.apache.felix.main-5.4.0.jar"))
-                .as(JavaArchive.class);
-    }
-
-    @Deployment(name="ConfigAdmin")
-    public static JavaArchive deployConfigAdmin() {
-        return ShrinkWrap.create(ZipImporter.class, "configadmin-1.8.8.jar")
-                .importFrom(new File("src/container/org.apache.felix.configadmin-1.8.8.jar"))
-                .as(JavaArchive.class);
-    }
-
-    @Deployment(name="tamaya-api")
-    public static JavaArchive deployTamayaAPI() {
-        return ShrinkWrap.create(ZipImporter.class, "tamaya-api.jar")
-                .importFrom(getBundleFile("tamaya-api:"+TAMAYA_VERSION))
-                .as(JavaArchive.class);
-    }
-
-    @Deployment(name="tamaya-core")
-    public static JavaArchive deployTamayaCore() {
-        return ShrinkWrap.create(ZipImporter.class, "tamaya-core.jar")
-                .importFrom(getBundleFile("tamaya-core:"+TAMAYA_VERSION))
-                .as(JavaArchive.class);
-    }
-
-    @Deployment(name="javax.annotation")
-    public static JavaArchive deployJavaxAnnotation() {
-        return ShrinkWrap.create(ZipImporter.class, "javax.annotation.jar")
-                .importFrom(Maven.configureResolver()
-                        .withMavenCentralRepo(false)
-                        .withClassPathResolution(true)
-                        .resolve("org.apache.geronimo.specs:geronimo-annotation_1.2_spec:1.0-alpha-1")
-                        .withoutTransitivity().asSingleFile())
-                .as(JavaArchive.class);
-    }
-
-    private static File getBundleFile(String artifactId) {
-        // Check
-        return Maven.configureResolver()
-                .withMavenCentralRepo(false)
-                .withClassPathResolution(true)
-                .resolve("org.apache.tamaya:" + artifactId).withoutTransitivity().asSingleFile();
-    }
-
-
-    //////////////////////////////////////////////////////// Tests //////////////////////////////////
-
-
-    @Before
-    public void startBundles(){
-//        for(Bundle bundle:context.getBundles()){
-//            context
-//                bundle.start();
-        try{
-            context.getBundle(0).start();
-        } catch (BundleException e) {
-            e.printStackTrace();
-        }
-//        }
-    }
-
-    @Test @Ignore
-    public void testTamayaPersistenceManagerAvailable(@ArquillianResource Bundle bundle) throws Exception {
-        ServiceReference<PersistenceManager> configRef = context.getServiceReference(PersistenceManager.class);
-        // TODO continue here...
-        assertNotNull(configRef);
-        PersistenceManager pm = context.getService(configRef);
-        assertNotNull(pm);
-        Dictionary tamayaConf = pm.load("tamaya-test");
-        assertNotNull(tamayaConf);
-        assertEquals("success!", tamayaConf.get("tamaya-test-property"));
-    }
-
-    @Test @Ignore
-    public void testTamayaConfigAvailableOnConfig() throws Exception {
-        ServiceReference<ConfigurationAdmin> configRef = context.getServiceReference(ConfigurationAdmin.class);
-        assertNotNull(configRef);
-        ConfigurationAdmin configAdmin = (ConfigurationAdmin)context.getService(configRef);
-        assertNotNull(configRef);
-        Configuration tamayaConf = configAdmin.getConfiguration("tamaya-test");
-        assertNotNull(tamayaConf);
-        assertEquals("success!", tamayaConf.getProperties().get("tamaya-test-property"));
-    }
-
-    @Test
-    public void testBundleContextInjection() throws Exception {
-        assertNotNull("BundleContext injected", context);
-        System.err.println(Arrays.toString(context.getBundles()));
-        assertEquals("System Bundle ID", 0, context.getBundle().getBundleId());
-    }
-
-}
\ No newline at end of file



[3/4] incubator-tamaya git commit: TAMAYA-129: OSGI Support. Partially tested.

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9d10e254/modules/integration/osgi/general/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/general/pom.xml b/modules/integration/osgi/general/pom.xml
index 5dfc7be..9b088ad 100644
--- a/modules/integration/osgi/general/pom.xml
+++ b/modules/integration/osgi/general/pom.xml
@@ -62,4 +62,35 @@
         </plugins>
     </build>
 
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.framework</artifactId>
+            <version>5.4.0</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.arquillian</groupId>
+            <artifactId>arquillian-bom</artifactId>
+            <version>1.1.10.Final</version>
+            <type>pom</type>
+            <scope>import</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.arquillian.junit</groupId>
+            <artifactId>arquillian-junit-container</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.arquillian.container</groupId>
+            <artifactId>arquillian-container-felix-embedded</artifactId>
+            <version>2.1.0.CR18</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+    </dependencies>
+
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9d10e254/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/general/Activator.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/general/Activator.java b/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/general/Activator.java
deleted file mode 100644
index c896c73..0000000
--- a/modules/integration/osgi/general/src/main/java/org/apache/tamaya/integration/osgi/general/Activator.java
+++ /dev/null
@@ -1,65 +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.integration.osgi.general;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationAdmin;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-/**
- * Activator that registers the Tamaya based Service Class for {@link ConfigurationAdmin},
- * using a default service priority of {@code 0}.
- */
-public class Activator implements BundleActivator {
-
-    private static final String SERVICE_RANKING_PROP = "org.tamaya.integration.cm.ranking";
-
-    private static final Integer DEFAULT_RANKING = Integer.MIN_VALUE + 100;
-
-    private BundleContext context;
-
-    ServiceRegistration<ConfigurationAdmin> registration;
-
-    @Override
-    public void start(BundleContext context) throws Exception {
-        Dictionary<String,Object> props = new Hashtable<>();
-        String ranking = context.getProperty(SERVICE_RANKING_PROP);
-        if (ranking == null) {
-            props.put(Constants.SERVICE_RANKING, DEFAULT_RANKING);
-        } else{
-            props.put(Constants.SERVICE_RANKING, Integer.valueOf(ranking));
-        }
-        this.context = context;
-        TamayaConfigAdminImpl cm = new TamayaConfigAdminImpl(context);
-        registration = context.registerService(ConfigurationAdmin.class, cm, null);
-    }
-
-    @Override
-    public void stop(BundleContext context) throws Exception {
-        if (registration != null) {
-            registration.unregister();
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9d10e254/modules/integration/osgi/injection/src/main/java/org/apache/tamaya/integration/osgi/injection/Activator.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/injection/src/main/java/org/apache/tamaya/integration/osgi/injection/Activator.java b/modules/integration/osgi/injection/src/main/java/org/apache/tamaya/integration/osgi/injection/Activator.java
index 561e0ae..b30ec81 100644
--- a/modules/integration/osgi/injection/src/main/java/org/apache/tamaya/integration/osgi/injection/Activator.java
+++ b/modules/integration/osgi/injection/src/main/java/org/apache/tamaya/integration/osgi/injection/Activator.java
@@ -19,26 +19,56 @@
 package org.apache.tamaya.integration.osgi.injection;
 
 import org.apache.tamaya.inject.ConfigurationInjection;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
+import org.osgi.framework.*;
+import org.osgi.util.tracker.ServiceTracker;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
 
 /**
  * Activator that injects Tamaya configuration into OSGI Services.
  */
 public class Activator implements ServiceListener, BundleActivator {
 
+    private static final Logger LOG = Logger.getLogger(Activator.class.getName());
+
     private BundleContext context;
+    private ServiceTracker<Object, Object> serviceTracker;
 
     @Override
     public void start(BundleContext context) throws Exception {
         this.context = context;
+        serviceTracker = new ServiceTracker<Object, Object>(context, Object.class, null) {
+            @Override
+            public Object addingService(ServiceReference<Object> reference) {
+                Object service = context.getService(reference);
+                Object pidObj = reference.getProperty(Constants.SERVICE_PID);
+                if (pidObj instanceof String) {
+                    String pid = (String) pidObj;
+                    try {
+                        ConfigurationInjection.getConfigurationInjector().configure(service);
+                    } catch (Exception e) {
+                        LOG.log(Level.WARNING, "Error configuring Service: " + service, e);
+                    }
+                } else {
+                    LOG.log(Level.SEVERE, "Unsupported pid: " + pidObj);
+                }
+                return service;
+            }
+
+            @Override
+            public void removedService(ServiceReference<Object> reference, Object service) {
+                context.ungetService(reference);
+            }
+        };
+        serviceTracker.open();
     }
 
     @Override
     public void stop(BundleContext context) throws Exception {
+        this.serviceTracker.close();
+        this.serviceTracker = null;
         this.context = null;
     }