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 2010/03/24 10:43:50 UTC

svn commit: r926995 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: BundleContextImpl.java FilterImpl.java

Author: rickhall
Date: Wed Mar 24 09:43:50 2010
New Revision: 926995

URL: http://svn.apache.org/viewvc?rev=926995&view=rev
Log:
Introduce new Filter implementation. (FELIX-2039)

Added:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/FilterImpl.java
Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java?rev=926995&r1=926994&r2=926995&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java Wed Mar 24 09:43:50 2010
@@ -98,8 +98,7 @@ class BundleContextImpl implements Felix
         throws InvalidSyntaxException
     {
         checkValidity();
-
-        return FrameworkUtil.createFilter(expr);
+        return new FilterImpl(expr);
     }
 
     public Bundle installBundle(String location)

Added: felix/trunk/framework/src/main/java/org/apache/felix/framework/FilterImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/FilterImpl.java?rev=926995&view=auto
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/FilterImpl.java (added)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/FilterImpl.java Wed Mar 24 09:43:50 2010
@@ -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.");
+        }
+    }
+}