felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r752486 - in /felix/trunk/fileinstall/src: main/java/org/apache/felix/fileinstall/ConfigurationKey.java main/java/org/apache/felix/fileinstall/DirectoryWatcher.java test/java/org/apache/felix/fileinstall/DirectoryWatcherTest.java
Date Wed, 11 Mar 2009 16:06:17 GMT
Author: rickhall
Date: Wed Mar 11 16:06:17 2009
New Revision: 752486

URL: http://svn.apache.org/viewvc?rev=752486&view=rev
Log:
Applied patch (FELIX-895) to fix configuration property handling.

Added:
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/ConfigurationKey.java
Modified:
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java
    felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/DirectoryWatcherTest.java

Added: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/ConfigurationKey.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/ConfigurationKey.java?rev=752486&view=auto
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/ConfigurationKey.java
(added)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/ConfigurationKey.java
Wed Mar 11 16:06:17 2009
@@ -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

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java?rev=752486&r1=752485&r2=752486&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java
(original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java
Wed Mar 11 16:06:17 2009
@@ -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

Modified: felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/DirectoryWatcherTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/DirectoryWatcherTest.java?rev=752486&r1=752485&r2=752486&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/DirectoryWatcherTest.java
(original)
+++ felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/DirectoryWatcherTest.java
Wed Mar 11 16:06:17 2009
@@ -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 );



Mime
View raw message