Package org.apache.felix.utils.filter
Class FilterImpl
- java.lang.Object
-
- org.apache.felix.utils.filter.FilterImpl
-
- All Implemented Interfaces:
org.osgi.framework.Filter
public class FilterImpl extends java.lang.Object implements 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 Classes Modifier and Type Class Description private static class
FilterImpl.CaseInsensitiveDictionary
This Dictionary is used for case-insensitive key lookup during filter evaluation.private static class
FilterImpl.Parser
Parser class for OSGi filter strings.private static class
FilterImpl.ServiceReferenceDictionary
This Dictionary is used for key lookup from a ServiceReference during filter evaluation.private static class
FilterImpl.SetAccessibleAction
-
Field Summary
Fields Modifier and Type Field Description private static int
AND
private static int
APPROX
private java.lang.String
attr
filter attribute or null if operation AND, OR or NOTprivate static java.lang.Class[]
constructorType
private java.lang.Object
converted
optim in case of versionprivate static int
EQUAL
private java.lang.String
filterString
private static int
GREATER
private static int
LESS
private static int
NOT
private int
op
filter operationprivate static int
OR
private static int
PRESENT
private static int
SUBSET
private static int
SUBSTRING
private static int
SUPERSET
private java.lang.Object
value
filter 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.String
approxString(java.lang.String input)
Map a string for an APPROX (~=) comparison.private boolean
compare(int operation, java.lang.Object value1, java.lang.Object value2)
private boolean
compare_Boolean(int operation, boolean boolval, java.lang.Object value2)
private boolean
compare_Byte(int operation, byte byteval, java.lang.Object value2)
private boolean
compare_Character(int operation, char charval, java.lang.Object value2)
private boolean
compare_Collection(int operation, java.util.Collection collection, java.lang.Object value2)
private boolean
compare_Comparable(int operation, java.lang.Comparable value1, java.lang.Object value2)
private boolean
compare_Double(int operation, double doubleval, java.lang.Object value2)
private boolean
compare_Float(int operation, float floatval, java.lang.Object value2)
private boolean
compare_Integer(int operation, int intval, java.lang.Object value2)
private boolean
compare_Long(int operation, long longval, java.lang.Object value2)
private boolean
compare_ObjectArray(int operation, java.lang.Object[] array, java.lang.Object value2)
private boolean
compare_PrimitiveArray(int operation, java.lang.Class type, java.lang.Object primarray, java.lang.Object value2)
private boolean
compare_Short(int operation, short shortval, java.lang.Object value2)
private boolean
compare_String(int operation, java.lang.String string, java.lang.Object value2)
private boolean
compare_Unknown(int operation, java.lang.Object value1, java.lang.Object value2)
private static java.lang.String
encodeValue(java.lang.String value)
Encode the value string such that '(', '*', ')' and '\' are escaped.boolean
equals(java.lang.Object obj)
Compares thisFilter
to anotherFilter
.private java.util.Collection
getSet(java.lang.Object value)
int
hashCode()
Returns the hashCode for thisFilter
.boolean
match(java.util.Dictionary dictionary)
Filter using aDictionary
.boolean
match(org.osgi.framework.ServiceReference reference)
Filter using a service's properties.private boolean
match0(java.util.Dictionary properties)
Internal match routine.private boolean
match0(java.util.Map properties)
boolean
matchCase(java.util.Dictionary dictionary)
Filter with case sensitivity using aDictionary
.boolean
matchCase(java.util.Map map)
Filter using aMap
.boolean
matches(java.util.Map<java.lang.String,?> map)
Filter using aMap
.static FilterImpl
newInstance(java.lang.String filterString)
Constructs aFilterImpl
object.static FilterImpl
newInstance(java.lang.String filterString, boolean ignoreCase)
private java.lang.String
normalize()
Returns thisFilter
's normalized filter string.java.lang.String
toString()
Returns thisFilter
's filter string.
-
-
-
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
-
SUBSET
private static final int SUBSET
- See Also:
- Constant Field Values
-
SUPERSET
private static final int SUPERSET
- 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
-
converted
private final java.lang.Object converted
optim in case of version
-
filterString
private transient volatile java.lang.String filterString
-
constructorType
private static final java.lang.Class[] constructorType
-
-
Method Detail
-
newInstance
public static FilterImpl newInstance(java.lang.String filterString) throws org.osgi.framework.InvalidSyntaxException
Constructs aFilterImpl
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.- 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(java.lang.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
Filter
is executed using the keys and values of the referenced service's properties. The keys are case insensitively matched with thisFilter
.- Specified by:
match
in interfaceorg.osgi.framework.Filter
- Parameters:
reference
- The reference to the service whose properties are used in the match.- Returns:
true
if the service's properties match thisFilter
;false
otherwise.
-
match
public boolean match(java.util.Dictionary dictionary)
Filter using aDictionary
. ThisFilter
is executed using the specifiedDictionary
's keys and values. The keys are case insensitively matched with thisFilter
.- Specified by:
match
in interfaceorg.osgi.framework.Filter
- Parameters:
dictionary
- TheDictionary
whose keys are used in the match.- Returns:
true
if theDictionary
's keys and values match this filter;false
otherwise.- Throws:
java.lang.IllegalArgumentException
- Ifdictionary
contains case variants of the same key name.
-
matchCase
public boolean matchCase(java.util.Dictionary dictionary)
Filter with case sensitivity using aDictionary
. ThisFilter
is executed using the specifiedDictionary
's keys and values. The keys are case sensitively matched with thisFilter
.- Specified by:
matchCase
in interfaceorg.osgi.framework.Filter
- Parameters:
dictionary
- TheDictionary
whose keys are used in the match.- Returns:
true
if theDictionary
's keys and values match this filter;false
otherwise.- Since:
- 1.3
-
matchCase
public boolean matchCase(java.util.Map map)
Filter using aMap
. ThisFilter
is executed using the specifiedMap
's keys and values. The keys are case insensitively matched with thisFilter
.- Parameters:
map
- TheMap
whose keys are used in the match.- Returns:
true
if theMap
's keys and values match this filter;false
otherwise.- Throws:
java.lang.IllegalArgumentException
- Ifmap
contains case variants of the same key name.
-
matches
public boolean matches(java.util.Map<java.lang.String,?> map)
Filter using aMap
. ThisFilter
is executed using the specifiedMap
's keys and values. The keys are looked up in a normal manner respecting case.- Specified by:
matches
in interfaceorg.osgi.framework.Filter
- Parameters:
map
- TheMap
whose key/value pairs are used in the match. Maps withnull
key or values are not supported. Anull
value is considered not present to the filter.- Returns:
true
if theMap
's values match this filter;false
otherwise.- Since:
- 1.6
-
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.
- Specified by:
toString
in interfaceorg.osgi.framework.Filter
- Overrides:
toString
in classjava.lang.Object
- Returns:
- This
Filter
's filter string.
-
normalize
private java.lang.String 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 thisFilter
to anotherFilter
.This implementation returns the result of calling
this.toString().equals(obj.toString()
.- Specified by:
equals
in interfaceorg.osgi.framework.Filter
- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- The object to compare against thisFilter
.- Returns:
- If the other object is a
Filter
object, then returns the result of callingthis.toString().equals(obj.toString()
;false
otherwise.
-
hashCode
public int hashCode()
Returns the hashCode for thisFilter
.This implementation returns the result of calling
this.toString().hashCode()
.- Specified by:
hashCode
in interfaceorg.osgi.framework.Filter
- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- The hashCode of this
Filter
.
-
match0
private boolean match0(java.util.Dictionary properties)
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
private boolean match0(java.util.Map properties)
-
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.
-
getSet
private java.util.Collection getSet(java.lang.Object value)
-
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)
-
compare_Comparable
private boolean compare_Comparable(int operation, java.lang.Comparable 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.
-
-