Class FrameworkUtil.FilterImpl
- java.lang.Object
-
- org.osgi.framework.FrameworkUtil.FilterImpl
-
- All Implemented Interfaces:
Filter
- Enclosing class:
- FrameworkUtil
private static final class FrameworkUtil.FilterImpl extends java.lang.Object implements Filter
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:
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 Classes Modifier and Type Class Description private static classFrameworkUtil.FilterImpl.ParserParser class for OSGi filter strings.
-
Field Summary
Fields Modifier and Type Field Description private static intANDprivate static intAPPROXprivate java.lang.Stringattrfilter attribute or null if operation AND, OR or NOTprivate static intEQUALprivate java.lang.StringfilterStringprivate static intGREATERprivate static intLESSprivate static intNOTprivate intopfilter operationprivate static intORprivate static intPRESENTprivate static intSUBSTRINGprivate java.lang.Objectvaluefilter operands
-
Constructor Summary
Constructors Constructor Description FilterImpl(int operation, java.lang.String attr, java.lang.Object value)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.StringapproxString(java.lang.String input)Map a string for an APPROX (~=) comparison.private booleancompare(int operation, java.lang.Object value1, java.lang.Object value2)private booleancompare_Boolean(int operation, boolean boolval, java.lang.Object value2)private booleancompare_Byte(int operation, byte byteval, java.lang.Object value2)private booleancompare_Character(int operation, char charval, java.lang.Object value2)private booleancompare_Collection(int operation, java.util.Collection<?> collection, java.lang.Object value2)private booleancompare_Comparable(int operation, java.lang.Comparable<java.lang.Object> value1, java.lang.Object value2)private booleancompare_Double(int operation, double doubleval, java.lang.Object value2)private booleancompare_Float(int operation, float floatval, java.lang.Object value2)private booleancompare_Integer(int operation, int intval, java.lang.Object value2)private booleancompare_Long(int operation, long longval, java.lang.Object value2)private booleancompare_ObjectArray(int operation, java.lang.Object[] array, java.lang.Object value2)private booleancompare_PrimitiveArray(int operation, java.lang.Class<?> type, java.lang.Object primarray, java.lang.Object value2)private booleancompare_Short(int operation, short shortval, java.lang.Object value2)private booleancompare_String(int operation, java.lang.String string, java.lang.Object value2)private booleancompare_Unknown(int operation, java.lang.Object value1, java.lang.Object value2)private booleancompare_Version(int operation, Version value1, java.lang.Object value2)private static java.lang.StringencodeValue(java.lang.String value)Encode the value string such that '(', '*', ')' and '\' are escaped.booleanequals(java.lang.Object obj)Compares thisFilterto anotherFilter.inthashCode()Returns the hashCode for thisFilter.booleanmatch(java.util.Dictionary<java.lang.String,?> dictionary)Filter using aDictionarywith case insensitive key lookup.booleanmatch(ServiceReference<?> reference)Filter using a service's properties.booleanmatchCase(java.util.Dictionary<java.lang.String,?> dictionary)Filter using aDictionary.booleanmatches(java.util.Map<java.lang.String,?> map)Filter using aMap.(package private) static FrameworkUtil.FilterImplnewInstance(java.lang.String filterString)Constructs aFrameworkUtil.FilterImplobject.private java.lang.StringBuildernormalize()Returns thisFilter's normalized filter string.private static voidsetAccessible(java.lang.reflect.AccessibleObject accessible)java.lang.StringtoString()Returns thisFilter's filter string.private static java.lang.ObjectvalueOf(java.lang.Class<?> target, java.lang.String value2)
-
-
-
Field Detail
-
EQUAL
private static final int EQUAL
- See Also:
- Constant Field Values
-
APPROX
private static final int APPROX
- See Also:
- Constant Field Values
-
GREATER
private static final int GREATER
- See Also:
- Constant Field Values
-
LESS
private static final int LESS
- See Also:
- Constant Field Values
-
PRESENT
private static final int PRESENT
- See Also:
- Constant Field Values
-
SUBSTRING
private static final int SUBSTRING
- See Also:
- Constant Field Values
-
AND
private static final int AND
- See Also:
- Constant Field Values
-
OR
private static final int OR
- See Also:
- Constant Field Values
-
NOT
private static final int NOT
- See Also:
- Constant Field Values
-
op
private final int op
filter operation
-
attr
private final java.lang.String attr
filter attribute or null if operation AND, OR or NOT
-
value
private final java.lang.Object value
filter operands
-
filterString
private transient java.lang.String filterString
-
-
Method Detail
-
newInstance
static FrameworkUtil.FilterImpl newInstance(java.lang.String filterString) throws InvalidSyntaxException
Constructs aFrameworkUtil.FilterImplobject. This filter object may be used to match aServiceReferenceor a Dictionary.If the filter cannot be parsed, an
InvalidSyntaxExceptionwill 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
public boolean match(ServiceReference<?> reference)
Filter using a service's properties.This
Filteris executed using the keys and values of the referenced service's properties. The keys are looked up in a case insensitive manner.
-
match
public boolean match(java.util.Dictionary<java.lang.String,?> dictionary)
Filter using aDictionarywith case insensitive key lookup. ThisFilteris executed using the specifiedDictionary's keys and values. The keys are looked up in a case insensitive manner.- Specified by:
matchin interfaceFilter- Parameters:
dictionary- TheDictionarywhose key/value pairs are used in the match.- Returns:
trueif theDictionary's values match this filter;falseotherwise.- Throws:
java.lang.IllegalArgumentException- Ifdictionarycontains case variants of the same key name.
-
matchCase
public boolean matchCase(java.util.Dictionary<java.lang.String,?> dictionary)
Filter using aDictionary. ThisFilteris executed using the specifiedDictionary's keys and values. The keys are looked up in a normal manner respecting case.
-
matches
public boolean matches(java.util.Map<java.lang.String,?> map)
Filter using aMap. ThisFilteris executed using the specifiedMap's keys and values. The keys are looked up in a normal manner respecting case.
-
toString
public java.lang.String toString()
Returns thisFilter's filter string.The filter string is normalized by removing whitespace which does not affect the meaning of the filter.
-
normalize
private java.lang.StringBuilder 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
public boolean equals(java.lang.Object obj)
Compares thisFilterto 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
private static java.lang.String encodeValue(java.lang.String value)
Encode the value string such that '(', '*', ')' and '\' are escaped.- Parameters:
value- unencoded value string.- Returns:
- encoded value string.
-
compare
private boolean compare(int operation, java.lang.Object value1, java.lang.Object value2)
-
compare_Collection
private boolean compare_Collection(int operation, java.util.Collection<?> collection, java.lang.Object value2)
-
compare_ObjectArray
private boolean compare_ObjectArray(int operation, java.lang.Object[] array, java.lang.Object value2)
-
compare_PrimitiveArray
private boolean compare_PrimitiveArray(int operation, java.lang.Class<?> type, java.lang.Object primarray, java.lang.Object value2)
-
compare_String
private boolean compare_String(int operation, java.lang.String string, java.lang.Object value2)
-
compare_Integer
private boolean compare_Integer(int operation, int intval, java.lang.Object value2)
-
compare_Long
private boolean compare_Long(int operation, long longval, java.lang.Object value2)
-
compare_Byte
private boolean compare_Byte(int operation, byte byteval, java.lang.Object value2)
-
compare_Short
private boolean compare_Short(int operation, short shortval, java.lang.Object value2)
-
compare_Character
private boolean compare_Character(int operation, char charval, java.lang.Object value2)
-
compare_Boolean
private boolean compare_Boolean(int operation, boolean boolval, java.lang.Object value2)
-
compare_Float
private boolean compare_Float(int operation, float floatval, java.lang.Object value2)
-
compare_Double
private boolean compare_Double(int operation, double doubleval, java.lang.Object value2)
-
valueOf
private static java.lang.Object valueOf(java.lang.Class<?> target, java.lang.String value2)
-
setAccessible
private static void setAccessible(java.lang.reflect.AccessibleObject accessible)
-
compare_Comparable
private boolean compare_Comparable(int operation, java.lang.Comparable<java.lang.Object> value1, java.lang.Object value2)
-
compare_Version
private boolean compare_Version(int operation, Version value1, java.lang.Object value2)
-
compare_Unknown
private boolean compare_Unknown(int operation, java.lang.Object value1, java.lang.Object value2)
-
approxString
private static java.lang.String approxString(java.lang.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.
-
-