public class FilterImpl extends Object implements Filter
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:
A filter matches a key that has multiple values if it matches at least one of those values. For example,Note: arrays of primitives are also supported.
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 Vector recursively applied to elements
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
.
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Compares this
Filter object to another object. |
String[] |
getAttributes()
Returns all the attributes contained within this filter
|
String |
getPrimaryKeyValue(String primaryKey)
Returns the leftmost required primary key value for the filter to evaluate to true.
|
String |
getRequiredObjectClass()
Returns the leftmost required objectClass value for the filter to evaluate to true.
|
int |
hashCode()
Returns the hashCode for this
Filter object. |
boolean |
match(Dictionary<String,?> dictionary)
Filter using a
Dictionary with case insensitive key lookup. |
boolean |
match(ServiceReference<?> reference)
Filter using a service's properties.
|
boolean |
matchCase(Dictionary<String,?> dictionary)
Filter using a
Dictionary . |
boolean |
matches(Map<String,?> map)
Filter using a
Map . |
static FilterImpl |
newInstance(String filterString)
Constructs a
FilterImpl object. |
String |
toString()
Returns this
Filter object's filter string. |
public static FilterImpl newInstance(String filterString) throws InvalidSyntaxException
FilterImpl
object. This filter object may be used
to match a ServiceReferenceImpl
or a Dictionary.
If the filter cannot be parsed, an InvalidSyntaxException
will be thrown with a human readable message where the
filter became unparsable.
filterString
- the filter string.InvalidSyntaxException
- If the filter parameter contains
an invalid filter string that cannot be parsed.public boolean match(ServiceReference<?> reference)
This Filter
is executed using the keys and values of the
referenced service's properties. The keys are looked up in a case
insensitive manner.
public boolean match(Dictionary<String,?> dictionary)
Dictionary
with case insensitive key lookup. This
Filter
is executed using the specified Dictionary
's keys
and values. The keys are looked up in a case insensitive manner.match
in interface Filter
dictionary
- The Dictionary
whose key/value pairs are used
in the match.true
if the Dictionary
's values match this
filter; false
otherwise.IllegalArgumentException
- If dictionary
contains case
variants of the same key name.public boolean matchCase(Dictionary<String,?> dictionary)
Dictionary
. This Filter
is executed using
the specified Dictionary
's keys and values. The keys are looked
up in a normal manner respecting case.public boolean matches(Map<String,?> map)
Map
. This Filter
is executed using the
specified Map
's keys and values. The keys are looked up in a
normal manner respecting case.public String toString()
Filter
object's filter string.
The filter string is normalized by removing whitespace which does not affect the meaning of the filter.
public boolean equals(Object obj)
Filter
object to another object.public int hashCode()
Filter
object.public String getRequiredObjectClass()
public String getPrimaryKeyValue(String primaryKey)
primaryKey
- the primary keypublic String[] getAttributes()
Copyright © 2007–2018 The Apache Software Foundation. All rights reserved.