@NotExtensible @ThreadSafety(level=INTERFACE_NOT_THREADSAFE) public abstract class JSONObjectFilter extends java.lang.Object implements java.io.Serializable
toLDAPFilter(String)
method can be used to easily create an LDAP
filter from a JSON object filter. This filter will have an attribute type
that is the name of an attribute with the JSON object syntax, a matching rule
ID of "jsonObjectFilterExtensibleMatch", and an assertion value that is the
string representation of the JSON object that comprises the filter.
NOTE: This class, and other classes within the
com.unboundid.ldap.sdk.unboundidds
package structure, are only
supported for use against Ping Identity, UnboundID, and
Nokia/Alcatel-Lucent 8661 server products. These classes provide support
for proprietary functionality or for external specifications that are not
considered stable or mature enough to be guaranteed to work in an
interoperable way with other types of LDAP servers.
{ "filterType" : "equals", "field" : "firstName", "value" : "John" }the resulting LDAP filter targeting attribute "jsonAttr" would have a string representation as follows (without the line break that has been added for formatting purposes):
(jsonAttr:jsonObjectFilterExtensibleMatch:={ "filterType" : "equals", "field" : "firstName", "value" : "John" })
{ "filterType" : "containsField", "field" : "department" }
{ "filterType" : "equals", "field" : "firstName", "value" : "John" }
{ "filterType" : "equalsAny", "field" : "userType", "values" : [ "employee", "partner", "contractor" ] }
{ "filterType" : "greaterThan", "field" : "salary", "value" : 50000, "allowEquals" : true }
{ "filterType" : "lessThan", "field" : "loginFailureCount", "value" : 3, "allowEquals" : true }
{ "filterType" : "substring", "field" : "email", "endsWith" : "@example.com" }
{ "filterType" : "regularExpression", "field" : "userID", "regularExpression" : "^[a-zA-Z][a-zA-Z0-9]*$" }
{ "filterType" : "objectMatches", "field" : "contact", "filter" : { "filterType" : "and", "andFilters" : [ { "filterType" : "equals", "field" : "type", "value" : "home" }, { "filterType" : "containsField", "field" : "email" } ] } }
{ "filterType" : "and", "andFilters" : [ { "filterType" : "equals", "field" : "firstName", "value" : "John" }, { "filterType" : "equals", "field" : "lastName", "value" : "Doe" } ] }
{ "filterType" : "or", "orFilters" : [ { "filterType" : "containsField", "field" : "homePhone" }, { "filterType" : "containsField", "field" : "workPhone" } ] }
{ "filterType" : "negate", "negateFilter" : { "filterType" : "equals", "field" : "userType", "value" : "employee" } }
{ "field1" : "valueA", "field2" : { "field3" : "valueB", "field4" : { "field5" : "valueC" } } }In the above example, the field whose value is
"valueA"
can be
targeted using either "field1"
or [ "field1" ]
. The field
whose value is "valueB"
can be targeted as
[ "field2", "field3" ]
. The field whose value is "valueC"
can be targeted as [ "field2", "field4", "field5" ]
.
{ "contact" : [ { "type" : "Home", "email" : "jdoe@example.net", "phone" : "123-456-7890" }, { "type" : "Work", "email" : "john.doe@example.com", "phone" : "789-456-0123" } ] }The field specifier
[ "contact", "type" ]
can reference either the
field whose value is "Home"
or the field whose value is
"Work"
. The field specifier [ "contact", "email" ]
can
reference the field whose value is "jdoe@example.net"
or the field
whose value is "john.doe@example.com"
. And the field specifier
[ "contact", "phone" ]
can reference the field with value
"123-456-7890"
or the field with value "789-456-0123"
. This
ambiguity is intentional for values in arrays because it makes it possible
to target array elements without needing to know the order of elements in the
array.
toLDAPFilter(java.lang.String)
method and
JSON objects created using the toJSONObject()
method will be
threadsafe under all circumstances.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
FIELD_FILTER_TYPE
The name of the JSON field that is used to specify the filter type for
the JSON object filter.
|
static java.lang.String |
JSON_OBJECT_FILTER_MATCHING_RULE_NAME
The name of the matching rule that may be used to determine whether an
attribute value matches a JSON object filter.
|
static java.lang.String |
JSON_OBJECT_FILTER_MATCHING_RULE_OID
The numeric OID of the matching rule that may be used to determine whether
an attribute value matches a JSON object filter.
|
Constructor and Description |
---|
JSONObjectFilter() |
Modifier and Type | Method and Description |
---|---|
static JSONObjectFilter |
decode(JSONObject o)
Decodes the provided JSON object as a JSON object filter.
|
protected abstract JSONObjectFilter |
decodeFilter(JSONObject o)
Decodes the provided JSON object as a filter of this type.
|
boolean |
equals(java.lang.Object o)
Indicates whether the provided object is considered equal to this JSON
object filter.
|
protected boolean |
getBoolean(JSONObject o,
java.lang.String fieldName,
java.lang.Boolean defaultValue)
Retrieves the value of the specified field from the provided JSON object as
a
boolean . |
protected java.util.List<JSONObjectFilter> |
getFilters(JSONObject o,
java.lang.String fieldName)
Retrieves the value of the specified field from the provided JSON object as
a list of JSON object filters.
|
abstract java.lang.String |
getFilterType()
Retrieves the value that must appear in the
filterType field for
this filter. |
protected abstract java.util.Set<java.lang.String> |
getOptionalFieldNames()
Retrieves the names of all fields that may optionally be present but are
not required in the JSON object representing a filter of this type.
|
protected abstract java.util.Set<java.lang.String> |
getRequiredFieldNames()
Retrieves the names of all fields (excluding the
filterType field)
that must be present in the JSON object representing a filter of this type. |
protected java.lang.String |
getString(JSONObject o,
java.lang.String fieldName,
java.lang.String defaultValue,
boolean required)
Retrieves the value of the specified field from the provided JSON object as
a strings.
|
protected java.util.List<java.lang.String> |
getStrings(JSONObject o,
java.lang.String fieldName,
boolean allowEmpty,
java.util.List<java.lang.String> defaultValues)
Retrieves the value of the specified field from the provided JSON object as
a list of strings.
|
protected static java.util.List<JSONValue> |
getValues(JSONObject o,
java.util.List<java.lang.String> fieldName)
Retrieves the set of values that match the provided field name specifier.
|
int |
hashCode()
Retrieves a hash code for this JSON object filter.
|
abstract boolean |
matchesJSONObject(JSONObject o)
Indicates whether this JSON object filter matches the provided JSON object.
|
protected static void |
registerFilterType(JSONObjectFilter... impl)
Registers the provided filter type(s) so that this class can decode filters
of that type.
|
abstract JSONObject |
toJSONObject()
Retrieves a JSON object that represents this filter.
|
Filter |
toLDAPFilter(java.lang.String attributeDescription)
Constructs an LDAP extensible matching filter that may be used to identify
entries with one or more values for a specified attribute that represent
JSON objects matching this JSON object filter.
|
abstract JSONObject |
toNormalizedJSONObject()
Retrieves a JSON object that represents a normalized version of this
filter.
|
java.lang.String |
toNormalizedString()
Retrieves a normalized string representation of the JSON object that
represents this filter.
|
void |
toNormalizedString(java.lang.StringBuilder buffer)
Appends a normalized string representation of the JSON object that
represents this filter to the provided buffer.
|
java.lang.String |
toString()
Retrieves a string representation of the JSON object that represents this
filter.
|
void |
toString(java.lang.StringBuilder buffer)
Appends a string representation of the JSON object that represents this
filter to the provided buffer.
|
@NotNull public static final java.lang.String JSON_OBJECT_FILTER_MATCHING_RULE_NAME
@NotNull public static final java.lang.String JSON_OBJECT_FILTER_MATCHING_RULE_OID
@NotNull public static final java.lang.String FIELD_FILTER_TYPE
public JSONObjectFilter()
@NotNull public abstract java.lang.String getFilterType()
filterType
field for
this filter.filterType
field for
this filter.@NotNull protected abstract java.util.Set<java.lang.String> getRequiredFieldNames()
filterType
field)
that must be present in the JSON object representing a filter of this type.filterType
field)
that must be present in the JSON object representing a filter of
this type.@NotNull protected abstract java.util.Set<java.lang.String> getOptionalFieldNames()
public abstract boolean matchesJSONObject(@NotNull JSONObject o)
o
- The JSON object for which to make the determination.true
if this JSON object filter matches the provided JSON
object, or false
if not.@NotNull public abstract JSONObject toJSONObject()
@NotNull public abstract JSONObject toNormalizedJSONObject()
@NotNull protected java.util.List<java.lang.String> getStrings(@NotNull JSONObject o, @NotNull java.lang.String fieldName, boolean allowEmpty, @Nullable java.util.List<java.lang.String> defaultValues) throws JSONException
o
- The JSON object to examine. It must not be
null
.fieldName
- The name of a top-level field in the JSON object
that is expected to have a value that is a string
or an array of strings. It must not be
null
. It will be treated in a
case-sensitive manner.allowEmpty
- Indicates whether the value is allowed to be an
empty array.defaultValues
- The list of default values to return if the field
is not present. If this is null
, then a
JSONException
will be thrown if the
specified field is not present.JSONException
- If the object doesn't have the specified field and
no set of default values was provided, or if the
value of the specified field was not a string or
an array of strings.@Nullable protected java.lang.String getString(@NotNull JSONObject o, @NotNull java.lang.String fieldName, @Nullable java.lang.String defaultValue, boolean required) throws JSONException
o
- The JSON object to examine. It must not be
null
.fieldName
- The name of a top-level field in the JSON object
that is expected to have a value that is a string.
It must not be null
. It will be treated in a
case-sensitive manner.defaultValue
- The default values to return if the field is not
present. If this is null
and
required
is true
, then a
JSONException
will be thrown if the specified
field is not present.required
- Indicates whether the field is required to be present
in the object.JSONException
- If the object doesn't have the specified field, the
field is required, and no default value was
provided, or if the value of the specified field
was not a string.protected boolean getBoolean(@NotNull JSONObject o, @NotNull java.lang.String fieldName, @Nullable java.lang.Boolean defaultValue) throws JSONException
boolean
. The specified field must be a top-level field in the
JSON object, and it must have a value that is either true
or
false
.o
- The JSON object to examine. It must not be
null
.fieldName
- The name of a top-level field in the JSON object that
that is expected to have a value that is either
true
or false
.defaultValue
- The default value to return if the specified field
is not present in the JSON object. If this is
null
, then a JSONException
will be
thrown if the specified field is not present.JSONException
- If the object doesn't have the specified field and
no default value was provided, or if the value of
the specified field was neither true
nor
false
.@NotNull protected java.util.List<JSONObjectFilter> getFilters(@NotNull JSONObject o, @NotNull java.lang.String fieldName) throws JSONException
o
- The JSON object to examine. It must not be
null
.fieldName
- The name of a top-level field in the JSON object that is
expected to have a value that is an array of JSON
objects that represent valid JSON object filters. It
must not be null
.JSONException
- If the object doesn't have the specified field, or
if the value of that field is not an array of
JSON objects that represent valid JSON object
filters.@NotNull protected static java.util.List<JSONValue> getValues(@NotNull JSONObject o, @NotNull java.util.List<java.lang.String> fieldName)
o
- The JSON object to examine.fieldName
- The field name specifier for the values to retrieve.@NotNull public static JSONObjectFilter decode(@NotNull JSONObject o) throws JSONException
o
- The JSON object to be decoded as a JSON object filter.JSONException
- If the provided JSON object cannot be decoded as a
JSON object filter.@NotNull protected abstract JSONObjectFilter decodeFilter(@NotNull JSONObject o) throws JSONException
o
- The JSON object to be decoded. The caller will have already
validated that all required fields are present, and that it
does not have any fields that are neither required nor optional.JSONException
- If the provided JSON object cannot be decoded as a
valid filter of this type.protected static void registerFilterType(@NotNull JSONObjectFilter... impl)
impl
- The filter type implementation(s) to register.@NotNull public final Filter toLDAPFilter(@NotNull java.lang.String attributeDescription)
attributeDescription
- The attribute description (i.e., the
attribute name or numeric OID plus zero or
more attribute options) for the LDAP
attribute to target with this filter. It
must not be null
.public final int hashCode()
hashCode
in class java.lang.Object
public final boolean equals(@Nullable java.lang.Object o)
equals
in class java.lang.Object
o
- The object for which to make the determination.true
if the provided object is considered equal to this
JSON object filter, or false
if not.@NotNull public final java.lang.String toString()
toString
in class java.lang.Object
public final void toString(@NotNull java.lang.StringBuilder buffer)
buffer
- The buffer to which the information should be appended.@NotNull public final java.lang.String toNormalizedString()
public final void toNormalizedString(@NotNull java.lang.StringBuilder buffer)
buffer
- The buffer to which the information should be appended.