Add PRESENT operator to new filter impl. (FELIX-2039)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@926490 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java b/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
index 04edb93..466af81 100644
--- a/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
+++ b/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
@@ -331,6 +331,13 @@
private static boolean compare(Object lhs, Object rhsUnknown, int op)
{
+ // If this is a PRESENT operation, then just return true immediately
+ // since we wouldn't be here if the attribute wasn't present.
+ if (op == SimpleFilter.PRESENT)
+ {
+ return true;
+ }
+
// If the type is comparable, then we can just return the
// result immediately.
if (lhs instanceof Comparable)
diff --git a/framework/src/main/java/org/apache/felix/framework/capabilityset/SimpleFilter.java b/framework/src/main/java/org/apache/felix/framework/capabilityset/SimpleFilter.java
index f213b5f..42205e9 100644
--- a/framework/src/main/java/org/apache/felix/framework/capabilityset/SimpleFilter.java
+++ b/framework/src/main/java/org/apache/felix/framework/capabilityset/SimpleFilter.java
@@ -32,6 +32,7 @@
// TODO: FELIX3 - Should we handle substring as a separate operator or as a
// special case of string equality comparison?
public static final int SUBSTRING = 7;
+ public static final int PRESENT = 8;
private final String m_name;
private final Object m_value;
@@ -85,6 +86,9 @@
case SUBSTRING:
s = "(" + m_name + "=" + unparseSubstring((List<String>) m_value) + ")";
break;
+ case PRESENT:
+ s = "(" + m_name + "=*)";
+ break;
}
return s;
}
@@ -329,11 +333,17 @@
Object value = sb.toString();
// Check if the equality comparison is actually a substring
- // comparison.
+ // or present operation.
if (op == EQ)
{
List<String> values = parseSubstring((String) value);
- if (values.size() > 1)
+ if ((values.size() == 2)
+ && (values.get(0).length() == 0)
+ && (values.get(1).length() == 0))
+ {
+ op = PRESENT;
+ }
+ else if (values.size() > 1)
{
op = SUBSTRING;
value = values;