You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2005/10/30 08:47:53 UTC
svn commit: r329539 - in
/incubator/felix/trunk/framework/src/org/apache/felix/framework: Felix.java
FilterImpl.java Main.java ServiceRegistrationImpl.java SystemBundle.java
cache/DefaultBundleArchive.java util/CaseInsensitiveMap.java
util/StringMap.java
Author: rickhall
Date: Sun Oct 30 00:47:41 2005
New Revision: 329539
URL: http://svn.apache.org/viewcvs?rev=329539&view=rev
Log:
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.
Added:
incubator/felix/trunk/framework/src/org/apache/felix/framework/util/StringMap.java
- copied, changed from r293118, incubator/felix/trunk/framework/src/org/apache/felix/framework/util/CaseInsensitiveMap.java
Removed:
incubator/felix/trunk/framework/src/org/apache/felix/framework/util/CaseInsensitiveMap.java
Modified:
incubator/felix/trunk/framework/src/org/apache/felix/framework/Felix.java
incubator/felix/trunk/framework/src/org/apache/felix/framework/FilterImpl.java
incubator/felix/trunk/framework/src/org/apache/felix/framework/Main.java
incubator/felix/trunk/framework/src/org/apache/felix/framework/ServiceRegistrationImpl.java
incubator/felix/trunk/framework/src/org/apache/felix/framework/SystemBundle.java
incubator/felix/trunk/framework/src/org/apache/felix/framework/cache/DefaultBundleArchive.java
Modified: incubator/felix/trunk/framework/src/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/framework/src/org/apache/felix/framework/Felix.java?rev=329539&r1=329538&r2=329539&view=diff
==============================================================================
--- incubator/felix/trunk/framework/src/org/apache/felix/framework/Felix.java (original)
+++ incubator/felix/trunk/framework/src/org/apache/felix/framework/Felix.java Sun Oct 30 00:47:41 2005
@@ -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();
Modified: incubator/felix/trunk/framework/src/org/apache/felix/framework/FilterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/framework/src/org/apache/felix/framework/FilterImpl.java?rev=329539&r1=329538&r2=329539&view=diff
==============================================================================
--- incubator/felix/trunk/framework/src/org/apache/felix/framework/FilterImpl.java (original)
+++ incubator/felix/trunk/framework/src/org/apache/felix/framework/FilterImpl.java Sun Oct 30 00:47:41 2005
@@ -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();
Modified: incubator/felix/trunk/framework/src/org/apache/felix/framework/Main.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/framework/src/org/apache/felix/framework/Main.java?rev=329539&r1=329538&r2=329539&view=diff
==============================================================================
--- incubator/felix/trunk/framework/src/org/apache/felix/framework/Main.java (original)
+++ incubator/felix/trunk/framework/src/org/apache/felix/framework/Main.java Sun Oct 30 00:47:41 2005
@@ -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)
Modified: incubator/felix/trunk/framework/src/org/apache/felix/framework/ServiceRegistrationImpl.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/framework/src/org/apache/felix/framework/ServiceRegistrationImpl.java?rev=329539&r1=329538&r2=329539&view=diff
==============================================================================
--- incubator/felix/trunk/framework/src/org/apache/felix/framework/ServiceRegistrationImpl.java (original)
+++ incubator/felix/trunk/framework/src/org/apache/felix/framework/ServiceRegistrationImpl.java Sun Oct 30 00:47:41 2005
@@ -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
{
Modified: incubator/felix/trunk/framework/src/org/apache/felix/framework/SystemBundle.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/framework/src/org/apache/felix/framework/SystemBundle.java?rev=329539&r1=329538&r2=329539&view=diff
==============================================================================
--- incubator/felix/trunk/framework/src/org/apache/felix/framework/SystemBundle.java (original)
+++ incubator/felix/trunk/framework/src/org/apache/felix/framework/SystemBundle.java Sun Oct 30 00:47:41 2005
@@ -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,
Modified: incubator/felix/trunk/framework/src/org/apache/felix/framework/cache/DefaultBundleArchive.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/framework/src/org/apache/felix/framework/cache/DefaultBundleArchive.java?rev=329539&r1=329538&r2=329539&view=diff
==============================================================================
--- incubator/felix/trunk/framework/src/org/apache/felix/framework/cache/DefaultBundleArchive.java (original)
+++ incubator/felix/trunk/framework/src/org/apache/felix/framework/cache/DefaultBundleArchive.java Sun Oct 30 00:47:41 2005
@@ -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))
Copied: incubator/felix/trunk/framework/src/org/apache/felix/framework/util/StringMap.java (from r293118, incubator/felix/trunk/framework/src/org/apache/felix/framework/util/CaseInsensitiveMap.java)
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/framework/src/org/apache/felix/framework/util/StringMap.java?p2=incubator/felix/trunk/framework/src/org/apache/felix/framework/util/StringMap.java&p1=incubator/felix/trunk/framework/src/org/apache/felix/framework/util/CaseInsensitiveMap.java&r1=293118&r2=329539&rev=329539&view=diff
==============================================================================
--- incubator/felix/trunk/framework/src/org/apache/felix/framework/util/CaseInsensitiveMap.java (original)
+++ incubator/felix/trunk/framework/src/org/apache/felix/framework/util/StringMap.java Sun Oct 30 00:47:41 2005
@@ -19,32 +19,75 @@
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
+ * 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 intended to compare strings.
+ * since it is only intended to compare strings.
**/
-public class CaseInsensitiveMap extends TreeMap
+public class StringMap extends TreeMap
{
- public CaseInsensitiveMap()
+ public StringMap()
{
- super(new Comparator() {
- public int compare(Object o1, Object o2)
- {
- return o1.toString().compareToIgnoreCase(o2.toString());
- }
- });
+ this(true);
}
- public CaseInsensitiveMap(Map map)
+ public StringMap(boolean caseSensitive)
{
- this();
+ 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;
+ }
}
}