Class FrameworkUtil.FilterImpl
- All Implemented Interfaces:
Filter
- Enclosing class:
FrameworkUtil
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 Collection recursively applied to values
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 Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Parser class for OSGi filter strings. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
private final String
filter attribute or null if operation AND, OR or NOTprivate static final int
private String
private static final int
private static final int
private static final int
private final int
filter operationprivate static final int
private static final int
private static final int
private final Object
filter operands -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static String
approxString
(String input) Map a string for an APPROX (~=) comparison.private boolean
private boolean
compare_Boolean
(int operation, boolean boolval, Object value2) private boolean
compare_Byte
(int operation, byte byteval, Object value2) private boolean
compare_Character
(int operation, char charval, Object value2) private boolean
compare_Collection
(int operation, Collection<?> collection, Object value2) private boolean
compare_Comparable
(int operation, Comparable<Object> value1, Object value2) private boolean
compare_Double
(int operation, double doubleval, Object value2) private boolean
compare_Float
(int operation, float floatval, Object value2) private boolean
compare_Integer
(int operation, int intval, Object value2) private boolean
compare_Long
(int operation, long longval, Object value2) private boolean
compare_ObjectArray
(int operation, Object[] array, Object value2) private boolean
compare_PrimitiveArray
(int operation, Class<?> type, Object primarray, Object value2) private boolean
compare_Short
(int operation, short shortval, Object value2) private boolean
compare_String
(int operation, String string, Object value2) private boolean
compare_Unknown
(int operation, Object value1, Object value2) private static String
encodeValue
(String value) Encode the value string such that '(', '*', ')' and '\' are escaped.boolean
Compares thisFilter
to anotherFilter
.int
hashCode()
Returns the hashCode for thisFilter
.boolean
match
(Dictionary<String, ?> dictionary) Filter using aDictionary
with case insensitive key lookup.boolean
match
(ServiceReference<?> reference) Filter using a service's properties.boolean
matchCase
(Dictionary<String, ?> dictionary) Filter using aDictionary
.boolean
Filter using aMap
.(package private) static FrameworkUtil.FilterImpl
newInstance
(String filterString) Constructs aFrameworkUtil.FilterImpl
object.private StringBuffer
Returns thisFilter
's normalized filter string.private static void
setAccessible
(AccessibleObject accessible) toString()
Returns thisFilter
's filter string.private static Object
-
Field Details
-
EQUAL
private static final int EQUAL- See Also:
-
APPROX
private static final int APPROX- See Also:
-
GREATER
private static final int GREATER- See Also:
-
LESS
private static final int LESS- See Also:
-
PRESENT
private static final int PRESENT- See Also:
-
SUBSTRING
private static final int SUBSTRING- See Also:
-
AND
private static final int AND- See Also:
-
OR
private static final int OR- See Also:
-
NOT
private static final int NOT- See Also:
-
op
private final int opfilter operation -
attr
filter attribute or null if operation AND, OR or NOT -
value
filter operands -
filterString
-
-
Constructor Details
-
FilterImpl
-
-
Method Details
-
newInstance
Constructs aFrameworkUtil.FilterImpl
object. This filter object may be used to match aServiceReference
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.- Throws:
InvalidSyntaxException
- If the filter parameter contains an invalid filter string that cannot be parsed.
-
match
Filter using a service's properties.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. -
match
Filter using aDictionary
with case insensitive key lookup. ThisFilter
is executed using the specifiedDictionary
's keys and values. The keys are looked up in a case insensitive manner.- Specified by:
match
in interfaceFilter
- Parameters:
dictionary
- TheDictionary
whose key/value pairs are used in the match.- Returns:
true
if theDictionary
's values match this filter;false
otherwise.- Throws:
IllegalArgumentException
- Ifdictionary
contains case variants of the same key name.
-
matchCase
Filter using aDictionary
. ThisFilter
is executed using the specifiedDictionary
's keys and values. The keys are looked up in a normal manner respecting case. -
matches
Filter using aMap
. ThisFilter
is executed using the specifiedMap
's keys and values. The keys are looked up in a normal manner respecting case. -
toString
Returns thisFilter
's filter string.The filter string is normalized by removing whitespace which does not affect the meaning of the filter.
-
normalize
Returns thisFilter
'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
Compares thisFilter
to anotherFilter
.This implementation returns the result of calling
this.toString().equals(obj.toString()
. -
hashCode
public int hashCode()Returns the hashCode for thisFilter
.This implementation returns the result of calling
this.toString().hashCode()
. -
encodeValue
Encode the value string such that '(', '*', ')' and '\' are escaped.- Parameters:
value
- unencoded value string.- Returns:
- encoded value string.
-
compare
-
compare_Collection
-
compare_ObjectArray
-
compare_PrimitiveArray
-
compare_String
-
compare_Integer
-
compare_Long
-
compare_Byte
-
compare_Short
-
compare_Character
-
compare_Boolean
-
compare_Float
-
compare_Double
-
valueOf
-
setAccessible
-
compare_Comparable
-
compare_Unknown
-
approxString
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.
-