Modifications to support/implement Filter.matchCase() from the R4 spec;
made case-insensitive utility map more generic to simplify implementation.
Modified dependent pieces of code.


git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@329539 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/org/apache/felix/framework/Felix.java b/framework/src/org/apache/felix/framework/Felix.java
index d7a11bb..f206d0d 100644
--- a/framework/src/org/apache/felix/framework/Felix.java
+++ b/framework/src/org/apache/felix/framework/Felix.java
@@ -211,7 +211,7 @@
         // Initialize member variables.
         m_mgr = null;
         m_configProps = (configProps == null)
-            ? new MutablePropertyResolverImpl(new CaseInsensitiveMap()) : configProps;
+            ? new MutablePropertyResolverImpl(new StringMap(false)) : configProps;
         m_activeStartLevel = FelixConstants.FRAMEWORK_INACTIVE_STARTLEVEL;
         m_installRequestMap = new HashMap();
         m_installedBundleMap = new HashMap();
diff --git a/framework/src/org/apache/felix/framework/FilterImpl.java b/framework/src/org/apache/felix/framework/FilterImpl.java
index 1c8e579..280d265 100644
--- a/framework/src/org/apache/felix/framework/FilterImpl.java
+++ b/framework/src/org/apache/felix/framework/FilterImpl.java
@@ -20,7 +20,7 @@
 import java.io.IOException;
 import java.util.*;
 
-import org.apache.felix.framework.util.CaseInsensitiveMap;
+import org.apache.felix.framework.util.StringMap;
 import org.apache.felix.framework.util.ldap.*;
 import org.osgi.framework.*;
 
@@ -127,7 +127,7 @@
     {
         try
         {
-            m_mapper.setSource(dict);
+            m_mapper.setSource(dict, false);
             return m_evaluator.evaluate(m_mapper);
         }
         catch (AttributeNotFoundException ex)
@@ -169,7 +169,18 @@
 
     public boolean matchCase(Dictionary dictionary)
     {
-        // TODO: Implement Filter.matchCase()
+        try
+        {
+            m_mapper.setSource(dictionary, true);
+            return m_evaluator.evaluate(m_mapper);
+        }
+        catch (AttributeNotFoundException ex)
+        {
+            m_logger.log(LogWrapper.LOG_DEBUG, "FilterImpl: " + ex);
+        }
+        catch (EvaluationException ex)
+        {
+            m_logger.log(LogWrapper.LOG_ERROR, "FilterImpl: " + toString(), ex);        }
         return false;
     }
 
@@ -189,7 +200,7 @@
     static class SimpleMapper implements Mapper
     {
         private ServiceReference m_ref = null;
-        private Map m_map = null;
+        private StringMap m_map = null;
 
         public void setSource(ServiceReference ref)
         {
@@ -197,17 +208,23 @@
             m_map = null;
         }
 
-        public void setSource(Dictionary dict)
+        public void setSource(Dictionary dict, boolean caseSensitive)
         {
+            // Create a map if we don't have one.
+            
             if (m_map == null)
             {
-                m_map = new CaseInsensitiveMap();
+                m_map = new StringMap();
             }
             else
             {
                 m_map.clear();
             }
 
+            // Set case comparison accordingly.
+            m_map.setCaseSensitive(caseSensitive);
+
+            // Put all dictionary entries into the map.
             if (dict != null)
             {
                 Enumeration keys = dict.keys();
diff --git a/framework/src/org/apache/felix/framework/Main.java b/framework/src/org/apache/felix/framework/Main.java
index c49e232..11b29ad 100644
--- a/framework/src/org/apache/felix/framework/Main.java
+++ b/framework/src/org/apache/felix/framework/Main.java
@@ -23,8 +23,8 @@
 import java.util.Properties;
 
 import org.apache.felix.framework.cache.DefaultBundleCache;
-import org.apache.felix.framework.util.CaseInsensitiveMap;
 import org.apache.felix.framework.util.MutablePropertyResolverImpl;
+import org.apache.felix.framework.util.StringMap;
 
 /**
  * <p>
@@ -188,7 +188,7 @@
             // Now create an instance of the framework.
             m_felix = new Felix();
             m_felix.start(
-                new MutablePropertyResolverImpl(new CaseInsensitiveMap(configProps)),
+                new MutablePropertyResolverImpl(new StringMap(configProps, false)),
                 null);
         }
         catch (Exception ex)
diff --git a/framework/src/org/apache/felix/framework/ServiceRegistrationImpl.java b/framework/src/org/apache/felix/framework/ServiceRegistrationImpl.java
index 7cddeee..b10b595 100644
--- a/framework/src/org/apache/felix/framework/ServiceRegistrationImpl.java
+++ b/framework/src/org/apache/felix/framework/ServiceRegistrationImpl.java
@@ -20,7 +20,7 @@
 import java.security.PrivilegedExceptionAction;
 import java.util.*;
 
-import org.apache.felix.framework.util.CaseInsensitiveMap;
+import org.apache.felix.framework.util.StringMap;
 import org.osgi.framework.*;
 
 class ServiceRegistrationImpl implements ServiceRegistration
@@ -212,7 +212,7 @@
         // Create a case insensitive map.
         if (m_propMap == null)
         {
-            m_propMap = new CaseInsensitiveMap();
+            m_propMap = new StringMap(false);
         }
         else
         {
diff --git a/framework/src/org/apache/felix/framework/SystemBundle.java b/framework/src/org/apache/felix/framework/SystemBundle.java
index 5cd68f7..d0e101f 100644
--- a/framework/src/org/apache/felix/framework/SystemBundle.java
+++ b/framework/src/org/apache/felix/framework/SystemBundle.java
@@ -22,8 +22,8 @@
 import java.util.*;
 
 import org.apache.felix.framework.searchpolicy.*;
-import org.apache.felix.framework.util.CaseInsensitiveMap;
 import org.apache.felix.framework.util.FelixConstants;
+import org.apache.felix.framework.util.StringMap;
 import org.apache.felix.moduleloader.LibrarySource;
 import org.apache.felix.moduleloader.ResourceSource;
 import org.osgi.framework.*;
@@ -126,7 +126,7 @@
         }
 
         // Initialize header map as a case insensitive map.
-        Map map = new CaseInsensitiveMap();
+        Map map = new StringMap(false);
         map.put(FelixConstants.BUNDLE_VERSION, FelixConstants.FELIX_VERSION_VALUE);
         map.put(FelixConstants.BUNDLE_NAME, "System Bundle");
         map.put(FelixConstants.BUNDLE_DESCRIPTION,
diff --git a/framework/src/org/apache/felix/framework/cache/DefaultBundleArchive.java b/framework/src/org/apache/felix/framework/cache/DefaultBundleArchive.java
index 02d4bc0..d449099 100644
--- a/framework/src/org/apache/felix/framework/cache/DefaultBundleArchive.java
+++ b/framework/src/org/apache/felix/framework/cache/DefaultBundleArchive.java
@@ -716,7 +716,7 @@
             // Get manifest.
             Manifest mf = jarFile.getManifest();
             // Create a case insensitive map of manifest attributes.
-            Map map = new CaseInsensitiveMap(mf.getMainAttributes());
+            Map map = new StringMap(mf.getMainAttributes(), false);
             // If the request is for the current revision's header,
             // then cache it.
             if (revision == (getRevisionCount() - 1))
diff --git a/framework/src/org/apache/felix/framework/util/CaseInsensitiveMap.java b/framework/src/org/apache/felix/framework/util/CaseInsensitiveMap.java
deleted file mode 100644
index cee55e5..0000000
--- a/framework/src/org/apache/felix/framework/util/CaseInsensitiveMap.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- *   Copyright 2005 The Apache Software Foundation
- *
- *   Licensed 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.framework.util;
-
-import java.util.*;
-
-/**
- * Simple utility class that creates a case-insensitive map by
- * extending <tt>TreeMap</tt> and to use a case-insensitive
- * comparator. Any keys put into this map will be converted to
- * a <tt>String</tt> using the <tt>toString()</tt> method,
- * since it is intended to compare strings.
-**/
-public class CaseInsensitiveMap extends TreeMap
-{
-    public CaseInsensitiveMap()
-    {
-        super(new Comparator() {
-            public int compare(Object o1, Object o2)
-            {
-                return o1.toString().compareToIgnoreCase(o2.toString());
-            }
-        });
-    }
-    
-    public CaseInsensitiveMap(Map map)
-    {
-        this();
-        putAll(map);
-    }
-    
-    public Object put(Object key, Object value)
-    {
-        return super.put(key.toString(), value);
-    }
-}
\ No newline at end of file
diff --git a/framework/src/org/apache/felix/framework/util/StringMap.java b/framework/src/org/apache/felix/framework/util/StringMap.java
new file mode 100644
index 0000000..ae1aa90
--- /dev/null
+++ b/framework/src/org/apache/felix/framework/util/StringMap.java
@@ -0,0 +1,93 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.framework.util;
+
+import java.util.*;
+
+/**
+ * Simple utility class that creates a map for string-based keys by
+ * extending <tt>TreeMap</tt>. This map can be set to use case-sensitive
+ * or case-insensitive comparison when searching for the key.
+ * Any keys put into this map will be converted to
+ * a <tt>String</tt> using the <tt>toString()</tt> method,
+ * since it is only intended to compare strings.
+**/
+public class StringMap extends TreeMap
+{
+    public StringMap()
+    {
+        this(true);
+    }
+    
+    public StringMap(boolean caseSensitive)
+    {
+        super(new StringComparator(caseSensitive));
+    }
+    
+    public StringMap(Map map, boolean caseSensitive)
+    {
+        this(caseSensitive);
+        putAll(map);
+    }
+    
+    public Object put(Object key, Object value)
+    {
+        return super.put(key.toString(), value);
+    }
+    
+    public boolean isCaseSensitive()
+    {
+        return ((StringComparator) comparator()).isCaseSensitive();
+    }
+
+    public void setCaseSensitive(boolean b)
+    {
+        ((StringComparator) comparator()).setCaseSensitive(b);
+    }
+
+    private static class StringComparator implements Comparator
+    {
+        private boolean m_isCaseSensitive = true;
+
+        public StringComparator(boolean b)
+        {
+            m_isCaseSensitive = b;
+        }
+
+        public int compare(Object o1, Object o2)
+        {
+            if (m_isCaseSensitive)
+            {
+                return o1.toString().compareTo(o2.toString());
+            }
+            else
+            {
+                return o1.toString().compareToIgnoreCase(o2.toString());
+            }
+        }
+
+        public boolean isCaseSensitive()
+        {
+            return m_isCaseSensitive;
+        }
+
+        public void setCaseSensitive(boolean b)
+        {
+            m_isCaseSensitive = b;
+        }
+    }
+}
\ No newline at end of file