Search in sources :

Example 1 with VirtualListViewResponseControl

use of org.forgerock.opendj.ldap.controls.VirtualListViewResponseControl in project OpenAM by OpenRock.

the class SearchResults method get.

/**
     * Get search result attributes related to the search operation performed.
     * 
     * @param name
     *            Name of attribute to return, null if attribute is unknown or
     *            not found
     * @throws UMSException
     *             from accessor methods on LDAPVirtualListResponse control
     * 
     * @supported.api
     */
public Object get(String name) throws UMSException {
    //
    if (!isVLVAttrs(name)) {
        return m_attrHash == null ? null : m_attrHash.get(name);
    }
    //
    if (currentEntry == null)
        return null;
    List<Control> ctrls = currentEntry.getControls();
    if (ctrls == null && expectVlvResponse() == true) {
        //
        // Code to deal with response controls not being returned yet. It
        // instructs a small search with vlv ranage that expect one result
        // to
        // return so that the response is returned. This probe is only
        // launched if EXPECT_VLV_RESPONSE is set for true in SearchResults
        //
        PersistentObject parent = getParentContainer();
        synchronized (this) {
            // The following code fragment uses a test control that only
            // asks
            // one result to return. This is done so that the response
            // control
            // can be queried for the vlvContentCount. This is a search
            // probe to
            // get the vlvCount
            //
            String[] sortAttrNames = { "objectclass" };
            SortKey[] sortKeys = (SortKey[]) get(SearchResults.SORT_KEYS);
            String filter = (String) get(SearchResults.SEARCH_FILTER);
            Integer scopeVal = (Integer) get(SearchResults.SEARCH_SCOPE);
            int scope = scopeVal == null ? SearchControl.SCOPE_SUB : scopeVal.intValue();
            SearchControl testControl = new SearchControl();
            testControl.setVLVRange(1, 0, 0);
            if (sortKeys == null) {
                testControl.setSortKeys(sortAttrNames);
            } else {
                testControl.setSortKeys(sortKeys);
            }
            testControl.setSearchScope(scope);
            SearchResults testResults = parent.search(filter, sortAttrNames, testControl);
            while (testResults.hasMoreElements()) {
                // This while loop is required to
                // enumerate the result set to get the response control
                testResults.next();
            }
            // After all the hazzle, now the response should be in after the
            // search probe, use the probe's search results to get the vlv
            // related attribute(s). Set the internal flag not to launch
            // the probe again in subsequent get.
            //
            testResults.set(SearchResults.EXPECT_VLV_RESPONSE, Boolean.FALSE);
            return testResults.get(name);
        }
    }
    // the control can be null
    if (ctrls == null)
        return null;
    VirtualListViewResponseControl vlvResponse = null;
    //
    for (Control control : ctrls) {
        if (VirtualListViewResponseControl.OID.equals(control.getOID())) {
            vlvResponse = (VirtualListViewResponseControl) control;
        }
    }
    //
    if (vlvResponse != null) {
        if (name.equalsIgnoreCase(VLVRESPONSE_CONTENT_COUNT)) {
            return vlvResponse.getContentCount();
        } else if (name.equalsIgnoreCase(VLVRESPONSE_FIRST_POSITION)) {
            return vlvResponse.getTargetPosition();
        } else if (name.equalsIgnoreCase(VLVRESPONSE_RESULT_CODE)) {
            return vlvResponse.getResult().intValue();
        } else if (name.equalsIgnoreCase(VLVRESPONSE_CONTEXT)) {
            return vlvResponse.getValue().toString();
        }
    }
    //
    return null;
}
Also used : Control(org.forgerock.opendj.ldap.controls.Control) VirtualListViewResponseControl(org.forgerock.opendj.ldap.controls.VirtualListViewResponseControl) VirtualListViewResponseControl(org.forgerock.opendj.ldap.controls.VirtualListViewResponseControl)

Aggregations

Control (org.forgerock.opendj.ldap.controls.Control)1 VirtualListViewResponseControl (org.forgerock.opendj.ldap.controls.VirtualListViewResponseControl)1