Applied patch (FELIX-895) to fix configuration property handling.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@752486 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/fileinstall/src/main/java/org/apache/felix/fileinstall/ConfigurationKey.java b/fileinstall/src/main/java/org/apache/felix/fileinstall/ConfigurationKey.java
new file mode 100644
index 0000000..f8a4bc0
--- /dev/null
+++ b/fileinstall/src/main/java/org/apache/felix/fileinstall/ConfigurationKey.java
@@ -0,0 +1,80 @@
+/*
+ * 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.felix.fileinstall;
+
+public class ConfigurationKey
+{
+    private String factoryId;
+    private String pid;
+
+    public ConfigurationKey(String factoryId, String pid)
+    {
+        this.factoryId = factoryId;
+        this.pid = pid;
+    }
+
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((factoryId == null) ? 0 : factoryId.hashCode());
+        result = prime * result + ((pid == null) ? 0 : pid.hashCode());
+        return result;
+    }
+
+    public boolean equals(Object obj)
+    {
+        if (this == obj)
+        {
+            return true;
+        }
+        if (obj == null)
+        {
+            return false;
+        }
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        ConfigurationKey other = (ConfigurationKey) obj;
+        if (factoryId == null)
+        {
+            if (other.factoryId != null)
+            {
+                return false;
+            }
+        }
+        else if (!factoryId.equals(other.factoryId))
+        {
+            return false;
+        }
+        if (pid == null)
+        {
+            if (other.pid != null)
+            {
+                return false;
+            }
+        }
+        else if (!pid.equals(other.pid))
+        {
+            return false;
+        }
+        return true;
+    }
+}
\ No newline at end of file
diff --git a/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java b/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java
index 3eb6219..6eadf1f 100644
--- a/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java
+++ b/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java
@@ -73,6 +73,8 @@
 
     // Represents jars that could not be installed
     Set/* <Bundle> */ startupFailures = new HashSet();
+    
+    Map /*<ConfigurationKey, Configuration>*/ configurations = new HashMap();
 
     public DirectoryWatcher(Dictionary properties, BundleContext context)
     {
@@ -227,10 +229,6 @@
         String pid[] = parsePid(f.getName());
         Hashtable ht = new Hashtable();
         ht.putAll(p);
-        if (pid[1] != null)
-        {
-            ht.put(ALIAS_KEY, pid[1]);
-        }
         Configuration config = getConfiguration(pid[0], pid[1]);
         if (config.getBundleLocation() != null)
         {
@@ -253,6 +251,7 @@
         String pid[] = parsePid(f.getName());
         Configuration config = getConfiguration(pid[0], pid[1]);
         config.delete();
+        configurations.remove(new ConfigurationKey(pid[0], pid[1]));
         return true;
     }
 
@@ -281,26 +280,28 @@
     Configuration getConfiguration(String pid, String factoryPid)
         throws Exception
     {
-        ConfigurationAdmin cm = (ConfigurationAdmin) FileInstall.cmTracker.getService();
-        if (factoryPid != null)
-        {
-            String filter = "(|(" + ALIAS_KEY + "=" + factoryPid + ")(.alias_factory_pid=" + factoryPid + "))";
-            Configuration configs[] = cm.listConfigurations(filter);
-            if (configs == null || configs.length == 0)
-            {
-                return cm.createFactoryConfiguration(pid, null);
-            }
-            else
-            {
-                return configs[0];
-            }
-        }
-        else
-        {
-            return cm.getConfiguration(pid, null);
-        }
+    	ConfigurationKey ck = new ConfigurationKey(pid, factoryPid);
+    	if (configurations.containsKey(ck))
+    	{
+    		return (Configuration) configurations.get(ck);
+    	}
+    	else
+    	{
+    		ConfigurationAdmin cm = (ConfigurationAdmin) FileInstall.cmTracker.getService();
+    		Configuration newConfiguration = null;
+    		if (factoryPid!=null)
+    		{
+    			newConfiguration = cm.createFactoryConfiguration(pid, null);
+    		}
+    		else
+    		{
+    			newConfiguration = cm.getConfiguration(pid, null);
+    		}
+    		configurations.put(ck, newConfiguration);
+    		return newConfiguration;
+    	}
     }
-
+    
     /**
      * This is the core of this class.
      * Install bundles that were discovered, uninstall bundles that are gone
diff --git a/fileinstall/src/test/java/org/apache/felix/fileinstall/DirectoryWatcherTest.java b/fileinstall/src/test/java/org/apache/felix/fileinstall/DirectoryWatcherTest.java
index dc87374..5f89fae 100644
--- a/fileinstall/src/test/java/org/apache/felix/fileinstall/DirectoryWatcherTest.java
+++ b/fileinstall/src/test/java/org/apache/felix/fileinstall/DirectoryWatcherTest.java
@@ -176,9 +176,6 @@
     public void testGetNewFactoryConfiguration() throws Exception
     {
         mockConfigurationControl.replay();
-        mockConfigurationAdmin.listConfigurations( "" );
-        mockConfigurationAdminControl.setMatcher( MockControl.ALWAYS_MATCHER );
-        mockConfigurationAdminControl.setReturnValue( null );
         mockConfigurationAdmin.createFactoryConfiguration( "pid", null );
         mockConfigurationAdminControl.setReturnValue( mockConfiguration );
         mockConfigurationAdminControl.replay();
@@ -201,10 +198,8 @@
     public void testGetExistentFactoryConfiguration() throws Exception
     {
         mockConfigurationControl.replay();
-        mockConfigurationAdmin.listConfigurations( "" );
-        mockConfigurationAdminControl.setMatcher( MockControl.ALWAYS_MATCHER );
-        mockConfigurationAdminControl.setReturnValue( new Configuration[]
-            { mockConfiguration } );
+        mockConfigurationAdmin.createFactoryConfiguration( "pid", null );
+        mockConfigurationAdminControl.setReturnValue( mockConfiguration );
         mockConfigurationAdminControl.replay();
         mockBundleContext.createFilter( "" );
         mockBundleContextControl.setMatcher( MockControl.ALWAYS_MATCHER );