Class FilterImpl

java.lang.Object
org.apache.felix.utils.filter.FilterImpl
All Implemented Interfaces:
org.osgi.framework.Filter

public class FilterImpl extends Object implements org.osgi.framework.Filter
This filter implementation is based on the official OSGi filter with additional support for the SUPERSET (>*) and SUBSET (<*) operators. This filter also has a few optimizations (cached transformation).
  • Field Details

  • Constructor Details

    • FilterImpl

      FilterImpl(int operation, String attr, Object value)
  • Method Details

    • newInstance

      public static FilterImpl newInstance(String filterString) throws org.osgi.framework.InvalidSyntaxException
      Constructs a FilterImpl object. This filter object may be used to match a ServiceReference or a Dictionary.

      If the filter cannot be parsed, an InvalidSyntaxException will be thrown with a human readable message where the filter became unparsable.

      Parameters:
      filterString - the filter string.
      Returns:
      A new filter
      Throws:
      org.osgi.framework.InvalidSyntaxException - If the filter parameter contains an invalid filter string that cannot be parsed.
    • newInstance

      public static FilterImpl newInstance(String filterString, boolean ignoreCase) throws org.osgi.framework.InvalidSyntaxException
      Throws:
      org.osgi.framework.InvalidSyntaxException
    • match

      public boolean match(org.osgi.framework.ServiceReference reference)
      Filter using a service's properties.

      This Filter is executed using the keys and values of the referenced service's properties. The keys are case insensitively matched with this Filter.

      Specified by:
      match in interface org.osgi.framework.Filter
      Parameters:
      reference - The reference to the service whose properties are used in the match.
      Returns:
      true if the service's properties match this Filter; false otherwise.
    • match

      public boolean match(Dictionary dictionary)
      Filter using a Dictionary. This Filter is executed using the specified Dictionary's keys and values. The keys are case insensitively matched with this Filter.
      Specified by:
      match in interface org.osgi.framework.Filter
      Parameters:
      dictionary - The Dictionary whose keys are used in the match.
      Returns:
      true if the Dictionary's keys and values match this filter; false otherwise.
      Throws:
      IllegalArgumentException - If dictionary contains case variants of the same key name.
    • matchCase

      public boolean matchCase(Dictionary dictionary)
      Filter with case sensitivity using a Dictionary. This Filter is executed using the specified Dictionary's keys and values. The keys are case sensitively matched with this Filter.
      Specified by:
      matchCase in interface org.osgi.framework.Filter
      Parameters:
      dictionary - The Dictionary whose keys are used in the match.
      Returns:
      true if the Dictionary's keys and values match this filter; false otherwise.
      Since:
      1.3
    • matchCase

      public boolean matchCase(Map map)
      Filter using a Map. This Filter is executed using the specified Map's keys and values. The keys are case insensitively matched with this Filter.
      Parameters:
      map - The Map whose keys are used in the match.
      Returns:
      true if the Map's keys and values match this filter; false otherwise.
      Throws:
      IllegalArgumentException - If map contains case variants of the same key name.
    • matches

      public boolean matches(Map<String,?> map)
      Filter using a Map. This Filter is executed using the specified Map's keys and values. The keys are looked up in a normal manner respecting case.
      Specified by:
      matches in interface org.osgi.framework.Filter
      Parameters:
      map - The Map whose key/value pairs are used in the match. Maps with null key or values are not supported. A null value is considered not present to the filter.
      Returns:
      true if the Map's values match this filter; false otherwise.
      Since:
      1.6
    • toString

      public String toString()
      Returns this Filter's filter string.

      The filter string is normalized by removing whitespace which does not affect the meaning of the filter.

      Specified by:
      toString in interface org.osgi.framework.Filter
      Overrides:
      toString in class Object
      Returns:
      This Filter's filter string.
    • normalize

      private String normalize()
      Returns this Filter's normalized filter string.

      The filter string is normalized by removing whitespace which does not affect the meaning of the filter.

      Returns:
      This Filter's filter string.
    • equals

      public boolean equals(Object obj)
      Compares this Filter to another Filter.

      This implementation returns the result of calling this.toString().equals(obj.toString().

      Specified by:
      equals in interface org.osgi.framework.Filter
      Overrides:
      equals in class Object
      Parameters:
      obj - The object to compare against this Filter.
      Returns:
      If the other object is a Filter object, then returns the result of calling this.toString().equals(obj.toString(); false otherwise.
    • hashCode

      public int hashCode()
      Returns the hashCode for this Filter.

      This implementation returns the result of calling this.toString().hashCode().

      Specified by:
      hashCode in interface org.osgi.framework.Filter
      Overrides:
      hashCode in class Object
      Returns:
      The hashCode of this Filter.
    • match0

      private boolean match0(Dictionary properties)
      Internal match routine. Dictionary parameter must support case-insensitive get.
      Parameters:
      properties - A dictionary whose keys are used in the match.
      Returns:
      If the Dictionary's keys match the filter, return true. Otherwise, return false.
    • match0

      private boolean match0(Map properties)
    • encodeValue

      private static String encodeValue(String value)
      Encode the value string such that '(', '*', ')' and '\' are escaped.
      Parameters:
      value - unencoded value string.
      Returns:
      encoded value string.
    • getSet

      private Collection getSet(Object value)
    • compare

      private boolean compare(int operation, Object value1, Object value2)
    • compare_Collection

      private boolean compare_Collection(int operation, Collection collection, Object value2)
    • compare_ObjectArray

      private boolean compare_ObjectArray(int operation, Object[] array, Object value2)
    • compare_PrimitiveArray

      private boolean compare_PrimitiveArray(int operation, Class type, Object primarray, Object value2)
    • compare_String

      private boolean compare_String(int operation, String string, Object value2)
    • compare_Integer

      private boolean compare_Integer(int operation, int intval, Object value2)
    • compare_Long

      private boolean compare_Long(int operation, long longval, Object value2)
    • compare_Byte

      private boolean compare_Byte(int operation, byte byteval, Object value2)
    • compare_Short

      private boolean compare_Short(int operation, short shortval, Object value2)
    • compare_Character

      private boolean compare_Character(int operation, char charval, Object value2)
    • compare_Boolean

      private boolean compare_Boolean(int operation, boolean boolval, Object value2)
    • compare_Float

      private boolean compare_Float(int operation, float floatval, Object value2)
    • compare_Double

      private boolean compare_Double(int operation, double doubleval, Object value2)
    • compare_Comparable

      private boolean compare_Comparable(int operation, Comparable value1, Object value2)
    • compare_Unknown

      private boolean compare_Unknown(int operation, Object value1, Object value2)
    • approxString

      private static String approxString(String input)
      Map a string for an APPROX (~=) comparison. This implementation removes white spaces. This is the minimum implementation allowed by the OSGi spec.
      Parameters:
      input - Input string.
      Returns:
      String ready for APPROX comparison.