Class MatchedValuesRequestControl

  • All Implemented Interfaces:
    java.io.Serializable

    @NotMutable
    @ThreadSafety(level=COMPLETELY_THREADSAFE)
    public final class MatchedValuesRequestControl
    extends Control
    This class provides an implementation of the matched values request control as defined in RFC 3876. It should only be used with a search request, in which case it indicates that only attribute values matching at least one of the provided MatchedValuesFilters should be included in matching entries. That is, this control may be used to restrict the set of values included in the entries that are returned. This is particularly useful for multivalued attributes with a large number of values when only a small number of values are of interest to the client.

    There are no corresponding response controls included in the search result entry, search result reference, or search result done messages returned for the associated search request.

    Example

    The following example demonstrates the use of the matched values request control. It will cause only values of the "description" attribute to be returned in which those values start with the letter f:
     // Ensure that a test user has multiple description values.
     LDAPResult modifyResult = connection.modify(
          "uid=test.user,ou=People,dc=example,dc=com",
          new Modification(ModificationType.REPLACE,
               "description", // Attribute name
               "first", "second", "third", "fourth")); // Attribute values.
     assertResultCodeEquals(modifyResult, ResultCode.SUCCESS);
    
     // Perform a search to retrieve the test user entry without using the
     // matched values request control.  This should return all four description
     // values.
     SearchRequest searchRequest = new SearchRequest(
          "uid=test.user,ou=People,dc=example,dc=com", // Base DN
          SearchScope.BASE, // Scope
          Filter.createPresenceFilter("objectClass"), // Filter
          "description"); // Attributes to return.
     SearchResultEntry entryRetrievedWithoutControl =
          connection.searchForEntry(searchRequest);
     Attribute fullDescriptionAttribute =
          entryRetrievedWithoutControl.getAttribute("description");
     int numFullDescriptionValues = fullDescriptionAttribute.size();
    
     // Update the search request to include a matched values control that will
     // only return values that start with the letter "f".  In our test entry,
     // this should just match two values ("first" and "fourth").
     searchRequest.addControl(new MatchedValuesRequestControl(
          MatchedValuesFilter.createSubstringFilter("description", // Attribute
               "f", // subInitial component
               null, // subAny components
               null))); // subFinal component
     SearchResultEntry entryRetrievedWithControl =
          connection.searchForEntry(searchRequest);
     Attribute partialDescriptionAttribute =
          entryRetrievedWithControl.getAttribute("description");
     int numPartialDescriptionValues = partialDescriptionAttribute.size();
     
    See Also:
    Serialized Form
    • Constructor Detail

      • MatchedValuesRequestControl

        public MatchedValuesRequestControl​(@NotNull
                                           MatchedValuesFilter... filters)
        Creates a new matched values request control with the provided set of filters. It will not be be marked as critical.
        Parameters:
        filters - The set of filters to use for this control. At least one filter must be provided.
      • MatchedValuesRequestControl

        public MatchedValuesRequestControl​(@NotNull
                                           java.util.List<MatchedValuesFilter> filters)
        Creates a new matched values request control with the provided set of filters. It will not be be marked as critical.
        Parameters:
        filters - The set of filters to use for this control. At least one filter must be provided.
      • MatchedValuesRequestControl

        public MatchedValuesRequestControl​(boolean isCritical,
                                           @NotNull
                                           MatchedValuesFilter... filters)
        Creates a new matched values request control with the provided criticality and set of filters.
        Parameters:
        isCritical - Indicates whether this control should be marked critical.
        filters - The set of filters to use for this control. At least one filter must be provided.
      • MatchedValuesRequestControl

        public MatchedValuesRequestControl​(boolean isCritical,
                                           @NotNull
                                           java.util.List<MatchedValuesFilter> filters)
        Creates a new matched values request control with the provided criticality and set of filters.
        Parameters:
        isCritical - Indicates whether this control should be marked critical.
        filters - The set of filters to use for this control. At least one filter must be provided.
      • MatchedValuesRequestControl

        public MatchedValuesRequestControl​(@NotNull
                                           Control control)
                                    throws LDAPException
        Creates a new matched values request control which is decoded from the provided generic control.
        Parameters:
        control - The generic control to be decoded as a matched values request control.
        Throws:
        LDAPException - If the provided control cannot be decoded as a matched values request control.
    • Method Detail

      • getFilters

        @NotNull
        public MatchedValuesFilter[] getFilters()
        Retrieves the set of filters for this matched values request control.
        Returns:
        The set of filters for this matched values request control.
      • getControlName

        @NotNull
        public java.lang.String getControlName()
        Retrieves the user-friendly name for this control, if available. If no user-friendly name has been defined, then the OID will be returned.
        Overrides:
        getControlName in class Control
        Returns:
        The user-friendly name for this control, or the OID if no user-friendly name is available.
      • toJSONControl

        @NotNull
        public JSONObject toJSONControl()
        Retrieves a representation of this matched values request control as a JSON object. The JSON object uses the following fields:
        • oid -- A mandatory string field whose value is the object identifier for this control. For the matched values request control, the OID is "1.2.826.0.1.3344810.2.3".
        • control-name -- An optional string field whose value is a human-readable name for this control. This field is only intended for descriptive purposes, and when decoding a control, the oid field should be used to identify the type of control.
        • criticality -- A mandatory Boolean field used to indicate whether this control is considered critical.
        • value-base64 -- An optional string field whose value is a base64-encoded representation of the raw value for this matched values request control. Exactly one of the value-base64 and value-json fields must be present.
        • value-json -- An optional JSON object field whose value is a user-friendly representation of the value for this matched values request control. Exactly one of the value-base64 and value-json fields must be present, and if the value-json field is used, then it will use the following fields:
          • filters -- A mandatory, non-empty array field whose values are the string representations of the matched values filters to use.
        Overrides:
        toJSONControl in class Control
        Returns:
        A JSON object that contains a representation of this control.
      • decodeJSONControl

        @NotNull
        public static MatchedValuesRequestControl decodeJSONControl​(@NotNull
                                                                    JSONObject controlObject,
                                                                    boolean strict)
                                                             throws LDAPException
        Attempts to decode the provided object as a JSON representation of a matched values request control.
        Parameters:
        controlObject - The JSON object to be decoded. It must not be null.
        strict - Indicates whether to use strict mode when decoding the provided JSON object. If this is true, then this method will throw an exception if the provided JSON object contains any unrecognized fields. If this is false, then unrecognized fields will be ignored.
        Returns:
        The matched values request control that was decoded from the provided JSON object.
        Throws:
        LDAPException - If the provided JSON object cannot be parsed as a valid matched values request control.
      • toString

        public void toString​(@NotNull
                             java.lang.StringBuilder buffer)
        Appends a string representation of this LDAP control to the provided buffer.
        Overrides:
        toString in class Control
        Parameters:
        buffer - The buffer to which to append the string representation of this buffer.