Package org.apache.felix.utils.filter
Class FilterImpl
java.lang.Object
org.apache.felix.utils.filter.FilterImpl
- All Implemented Interfaces:
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).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classThis Dictionary is used for case-insensitive key lookup during filter evaluation.private static classParser class for OSGi filter strings.private static classThis Dictionary is used for key lookup from a ServiceReference during filter evaluation.private static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final intprivate final Stringfilter attribute or null if operation AND, OR or NOTprivate static final Class[]private final Objectoptim in case of versionprivate static final intprivate Stringprivate static final intprivate static final intprivate static final intprivate final intfilter operationprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate final Objectfilter operands -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringapproxString(String input) Map a string for an APPROX (~=) comparison.private booleanprivate booleancompare_Boolean(int operation, boolean boolval, Object value2) private booleancompare_Byte(int operation, byte byteval, Object value2) private booleancompare_Character(int operation, char charval, Object value2) private booleancompare_Collection(int operation, Collection collection, Object value2) private booleancompare_Comparable(int operation, Comparable value1, Object value2) private booleancompare_Double(int operation, double doubleval, Object value2) private booleancompare_Float(int operation, float floatval, Object value2) private booleancompare_Integer(int operation, int intval, Object value2) private booleancompare_Long(int operation, long longval, Object value2) private booleancompare_ObjectArray(int operation, Object[] array, Object value2) private booleancompare_PrimitiveArray(int operation, Class type, Object primarray, Object value2) private booleancompare_Short(int operation, short shortval, Object value2) private booleancompare_String(int operation, String string, Object value2) private booleancompare_Unknown(int operation, Object value1, Object value2) private static StringencodeValue(String value) Encode the value string such that '(', '*', ')' and '\' are escaped.booleanCompares thisFilterto anotherFilter.private CollectioninthashCode()Returns the hashCode for thisFilter.booleanmatch(Dictionary dictionary) Filter using aDictionary.booleanmatch(org.osgi.framework.ServiceReference reference) Filter using a service's properties.private booleanmatch0(Dictionary properties) Internal match routine.private booleanbooleanmatchCase(Dictionary dictionary) Filter with case sensitivity using aDictionary.booleanFilter using aMap.booleanFilter using aMap.static FilterImplnewInstance(String filterString) Constructs aFilterImplobject.static FilterImplnewInstance(String filterString, boolean ignoreCase) private StringReturns thisFilter's normalized filter string.toString()Returns thisFilter's filter string.
-
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:
-
SUBSET
private static final int SUBSET- See Also:
-
SUPERSET
private static final int SUPERSET- See Also:
-
op
private final int opfilter operation -
attr
filter attribute or null if operation AND, OR or NOT -
value
filter operands -
converted
optim in case of version -
filterString
-
constructorType
-
-
Constructor Details
-
FilterImpl
-
-
Method Details
-
newInstance
public static FilterImpl newInstance(String filterString) throws org.osgi.framework.InvalidSyntaxException Constructs aFilterImplobject. 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.- 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
Filteris executed using the keys and values of the referenced service's properties. The keys are case insensitively matched with thisFilter.- Specified by:
matchin interfaceorg.osgi.framework.Filter- Parameters:
reference- The reference to the service whose properties are used in the match.- Returns:
trueif the service's properties match thisFilter;falseotherwise.
-
match
Filter using aDictionary. ThisFilteris executed using the specifiedDictionary's keys and values. The keys are case insensitively matched with thisFilter.- Specified by:
matchin interfaceorg.osgi.framework.Filter- Parameters:
dictionary- TheDictionarywhose keys are used in the match.- Returns:
trueif theDictionary's keys and values match this filter;falseotherwise.- Throws:
IllegalArgumentException- Ifdictionarycontains case variants of the same key name.
-
matchCase
Filter with case sensitivity using aDictionary. ThisFilteris executed using the specifiedDictionary's keys and values. The keys are case sensitively matched with thisFilter.- Specified by:
matchCasein interfaceorg.osgi.framework.Filter- Parameters:
dictionary- TheDictionarywhose keys are used in the match.- Returns:
trueif theDictionary's keys and values match this filter;falseotherwise.- Since:
- 1.3
-
matchCase
Filter using aMap. ThisFilteris executed using the specifiedMap's keys and values. The keys are case insensitively matched with thisFilter.- Parameters:
map- TheMapwhose keys are used in the match.- Returns:
trueif theMap's keys and values match this filter;falseotherwise.- Throws:
IllegalArgumentException- Ifmapcontains case variants of the same key name.
-
matches
Filter using aMap. ThisFilteris executed using the specifiedMap's keys and values. The keys are looked up in a normal manner respecting case.- Specified by:
matchesin interfaceorg.osgi.framework.Filter- Parameters:
map- TheMapwhose key/value pairs are used in the match. Maps withnullkey or values are not supported. Anullvalue is considered not present to the filter.- Returns:
trueif theMap's values match this filter;falseotherwise.- Since:
- 1.6
-
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 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(). -
match0
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, returnfalse.
-
match0
-
encodeValue
Encode the value string such that '(', '*', ')' and '\' are escaped.- Parameters:
value- unencoded value string.- Returns:
- encoded value string.
-
getSet
-
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
-
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.
-