Introduce new Filter implementation. (FELIX-2039)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@926995 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
index 2248d5c..2c16eb7 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
@@ -98,8 +98,7 @@
throws InvalidSyntaxException
{
checkValidity();
-
- return FrameworkUtil.createFilter(expr);
+ return new FilterImpl(expr);
}
public Bundle installBundle(String location)
diff --git a/framework/src/main/java/org/apache/felix/framework/FilterImpl.java b/framework/src/main/java/org/apache/felix/framework/FilterImpl.java
new file mode 100644
index 0000000..1038067
--- /dev/null
+++ b/framework/src/main/java/org/apache/felix/framework/FilterImpl.java
@@ -0,0 +1,203 @@
+/*
+ * 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.framework;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.List;
+import javax.crypto.spec.IvParameterSpec;
+import org.apache.felix.framework.capabilityset.Attribute;
+import org.apache.felix.framework.capabilityset.Capability;
+import org.apache.felix.framework.capabilityset.CapabilitySet;
+import org.apache.felix.framework.capabilityset.Directive;
+import org.apache.felix.framework.capabilityset.SimpleFilter;
+import org.apache.felix.framework.resolver.Module;
+import org.apache.felix.framework.util.StringMap;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+public class FilterImpl implements Filter
+{
+ private final SimpleFilter m_filter;
+
+ public FilterImpl(String filterStr) throws InvalidSyntaxException
+ {
+ try
+ {
+ m_filter = SimpleFilter.parse(filterStr);
+ }
+ catch (Throwable th)
+ {
+ throw new InvalidSyntaxException(th.getMessage(), filterStr);
+ }
+ }
+
+ public boolean match(ServiceReference sr)
+ {
+ return CapabilitySet.matches(new ServiceReferenceCapability(sr), m_filter);
+ }
+
+ public boolean match(Dictionary dctnr)
+ {
+ return CapabilitySet.matches(new DictionaryCapability(dctnr, false), m_filter);
+ }
+
+ public boolean matchCase(Dictionary dctnr)
+ {
+ return CapabilitySet.matches(new DictionaryCapability(dctnr, true), m_filter);
+ }
+
+ public boolean equals(Object o)
+ {
+ return toString().equals(o.toString());
+ }
+
+ public int hashCode()
+ {
+ return toString().hashCode();
+ }
+
+ public String toString()
+ {
+ return m_filter.toString();
+ }
+
+ static class DictionaryCapability implements Capability
+ {
+ private final StringMap m_map;
+
+ public DictionaryCapability(Dictionary dict, boolean caseSensitive)
+ {
+ m_map = new StringMap(caseSensitive);
+ if (dict != null)
+ {
+ Enumeration keys = dict.keys();
+ while (keys.hasMoreElements())
+ {
+ Object key = keys.nextElement();
+ if (m_map.get(key) == null)
+ {
+ m_map.put(key, new Attribute((String) key, dict.get(key), false));
+ }
+ else
+ {
+ throw new IllegalArgumentException(
+ "Duplicate attribute: " + key.toString());
+ }
+ }
+ }
+ }
+
+ public Module getModule()
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getNamespace()
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Directive getDirective(String name)
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public List<Directive> getDirectives()
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Attribute getAttribute(String name)
+ {
+ return (Attribute) m_map.get(name);
+ }
+
+ public List<Attribute> getAttributes()
+ {
+ return new ArrayList(m_map.values());
+ }
+
+ public List<String> getUses()
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ }
+
+ static class ServiceReferenceCapability implements Capability
+ {
+ private final StringMap m_map;
+
+ public ServiceReferenceCapability(ServiceReference sr)
+ {
+ m_map = new StringMap(false);
+
+ String[] keys = sr.getPropertyKeys();
+ for (int i = 0; i < keys.length; i++)
+ {
+ if (m_map.get(keys[i]) == null)
+ {
+ m_map.put(keys[i], new Attribute(keys[i], sr.getProperty(keys[i]), false));
+ }
+ else
+ {
+ throw new IllegalArgumentException(
+ "Duplicate attribute: " + keys[i].toString());
+ }
+ }
+ }
+
+ public Module getModule()
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getNamespace()
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Directive getDirective(String name)
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public List<Directive> getDirectives()
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Attribute getAttribute(String name)
+ {
+ return (Attribute) m_map.get(name);
+ }
+
+ public List<Attribute> getAttributes()
+ {
+ return new ArrayList(m_map.values());
+ }
+
+ public List<String> getUses()
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ }
+}