Top Description Inners Fields Constructors Methods
org.osgi.framework

pack-priv abstract Class FilterImpl

extends Object
implements Filter
Class Inheritance
All Implemented Interfaces
org.osgi.framework.Filter
Known Direct Subclasses
org.osgi.framework.FilterImpl.And, org.osgi.framework.FilterImpl.Or, org.osgi.framework.FilterImpl.Not, org.osgi.framework.FilterImpl.Item
Static Imports
java.util.Objects.requireNonNull

RFC 1960-based Filter. Filter objects can be created by calling the constructor with the desired filter string. A Filter object can be called numerous times to determine if the match argument matches the filter string that was used to create the Filter object.

The syntax of a filter string is the string representation of LDAP search filters as defined in RFC 1960: A String Representation of LDAP Search Filters (available at http://www.ietf.org/rfc/rfc1960.txt). It should be noted that RFC 2254: A String Representation of LDAP Search Filters (available at http://www.ietf.org/rfc/rfc2254.txt) supersedes RFC 1960 but only adds extensible matching and is not applicable for this API.

The string representation of an LDAP search filter is defined by the following grammar. It uses a prefix format.

  <filter> ::= '(' <filtercomp> ')'
  <filtercomp> ::= <and> | <or> | <not> | <item>
  <and> ::= '&' <filterlist>
  <or> ::= '|' <filterlist>
  <not> ::= '!' <filter>
  <filterlist> ::= <filter> | <filter> <filterlist>
  <item> ::= <simple> | <present> | <substring>
  <simple> ::= <attr> <filtertype> <value>
  <filtertype> ::= <equal> | <approx> | <greater> | <less>
  <equal> ::= '='
  <approx> ::= '˜='
  <greater> ::= '>='
  <less> ::= '<='
  <present> ::= <attr> '=*'
  <substring> ::= <attr> '=' <initial> <any> <final>
  <initial> ::= NULL | <value>
  <any> ::= '*' <starval>
  <starval> ::= NULL | <value> '*' <starval>
  <final> ::= NULL | <value>
<attr> is a string representing an attribute, or key, in the properties objects of the registered services. Attribute names are not case sensitive; that is cn and CN both refer to the same attribute. <value> is a string representing the value, or part of one, of a key in the properties objects of the registered services. If a <value> must contain one of the characters ' *' or '(' or ')', these characters should be escaped by preceding them with the backslash '\' character. Note that although both the <substring> and <present> productions can produce the 'attr=*' construct, this construct is used only to denote a presence filter.

Examples of LDAP filters are:

  "(cn=Babs Jensen)"
  "(!(cn=Tim Howes))"
  "(&(" + Constants.OBJECTCLASS + "=Person)(|(sn=Jensen)(cn=Babs J*)))"
  "(o=univ*of*mich*)"

The approximate match (~=) is implementation specific but should at least ignore case and white space differences. Optional are codes like soundex or other smart "closeness" comparisons.

Comparison of values is not straightforward. Strings are compared differently than numbers and it is possible for a key to have multiple values. Note that that keys in the match argument must always be strings. The comparison is defined by the object type of the key's value. The following rules apply for comparison:

Property Value Type Comparison Type
String String comparison
Integer, Long, Float, Double, Byte, Short, BigInteger, BigDecimal numerical comparison
Character character comparison
Boolean equality comparisons only
[] (array) recursively applied to values
Collection recursively applied to values
Note: arrays of primitives are also supported.
A filter matches a key that has multiple values if it matches at least one of those values. For example,
Dictionary d = new Hashtable();
d.put("cn", new String[] {
		"a", "b", "c"
});
d will match (cn=a) and also (cn=b)

A filter component that references a key having an unrecognizable data type will evaluate to false .

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class
private static class
FilterImpl.CaseInsensitiveMap

This Map is used for case-insensitive key lookup during filter evaluation.

private static class
FilterImpl.DictionaryMap

This Map is used for key lookup during filter evaluation.

pack-priv static class
pack-priv static class
pack-priv abstract static class
pack-priv static class
pack-priv static class
pack-priv static class
private static class
FilterImpl.Parser

Parser class for OSGi filter strings.

pack-priv static class
private static class
FilterImpl.ServiceReferenceMap

This Map is used for key lookup from a ServiceReference during filter evaluation.

pack-priv static class

Field Summary

Modifier and TypeField and Description
private transient String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static FilterImpl
createFilter(String
the filter string.
filterString
)

Creates a FilterImpl object.

public boolean

Returns:

If the other object is a Filter object, then returns the result of calling this.toString().equals(obj.toString(); false otherwise.
equals
(Object
The object to compare against this Filter.
obj
)

Overrides java.lang.Object.equals.

Implements org.osgi.framework.Filter.equals.

Compares this Filter to another Filter.

public int

Returns:

The hashCode of this Filter.
hashCode
()

Overrides java.lang.Object.hashCode.

Implements org.osgi.framework.Filter.hashCode.

Returns the hashCode for this Filter.

public boolean

Returns:

true if the service's properties match this Filter; false otherwise.
match
(ServiceReference<?>
The reference to the service whose properties are used in the match.
reference
)

Implements org.osgi.framework.Filter.match.

Filter using a service's properties.

public boolean

Returns:

true if the Dictionary's values match this filter; false otherwise.
match
(Dictionary<String, ?>
The Dictionary whose key/value pairs are used in the match.
dictionary
)

Implements org.osgi.framework.Filter.match.

Filter using a Dictionary with case insensitive key lookup.

public boolean

Returns:

true if the Dictionary's values match this filter; false otherwise.
matchCase
(Dictionary<String, ?>
The Dictionary whose key/value pairs are used in the match.
dictionary
)

Implements org.osgi.framework.Filter.matchCase.

Filter using a Dictionary.

public boolean

Returns:

true if the Map's values match this filter; false otherwise.
matches
(Map<String, ?>
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.
map
)

Implements org.osgi.framework.Filter.matches.

Filter using a Map.

pack-priv abstract boolean
matches0(Map<String, ?> map)

pack-priv abstract StringBuilder

Returns:

This Filter's filter string.
normalize
(StringBuilder sb)

Returns this Filter's normalized filter string.

public String

Returns:

This Filter's filter string.
toString
()

Overrides java.lang.Object.toString.

Implements org.osgi.framework.Filter.toString.

Returns this Filter's filter string.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait