Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
==================== DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved. Copyright 2011-2013 Tirasa. All rights reserved. The contents of this file are subject to the terms of the Common Development and Distribution License("CDDL") (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the License at See the License for the specific language governing permissions and limitations under the License. When distributing the Covered Code, include this CDDL Header Notice in each file and include the License file at If applicable, add the following below this CDDL Header, with the fields enclosed by brackets [] replaced by your own identifying information: "Portions Copyrighted [year] [name of copyright owner]" ====================
 import java.util.List;
     private static final Log LOG =
     private final int pageSize;
     static String searchControlsToString(SearchControls controls) {
         StringBuilder builder = new StringBuilder();
         builder.append("SearchControls: {returningAttributes=");
         String[] attrs = controls.getReturningAttributes();
         builder.append(attrs != null ? Arrays.asList(attrs) : "null");
         builder.append(", scope=");
         switch (controls.getSearchScope()) {
             case .:
             case .:
             case .:
         return builder.toString();
     public ADSimplePagedSearchStrategy(int pageSize) {
         this. = pageSize;
     public void doSearch(
             final LdapContext initCtx,
             final List<StringbaseDNs,
             final String query,
             final SearchControls searchControls,
             final SearchResultsHandler handler)
             throws IOExceptionNamingException {
         if (.isOk()) {
             .ok("Searching in {0} with filter {1} and {2}",
         LdapContext ctx = initCtx.newInstance(null);
         try {
             Iterator<StringbaseDNIter = baseDNs.iterator();
             boolean proceed = true;
             while (baseDNIter.hasNext() && proceed) {
                 String baseDN =;
                 byte[] cookie = null;
                 do {
                             new Control[]{new PagedResultsControl(
                    NamingEnumeration<SearchResultresults =
                    try {
                        // hasMore call for referral resolution ... it fails with AD
                        // while (proceed && results.hasMore()) {
                        while (proceed && results.hasMoreElements()) {
                            proceed = handler.handle(;
                    } finally {
                    cookie = getResponseCookie(ctx.getResponseControls());
                } while (cookie != null);
        } finally {
    private byte[] getResponseCookie(Control[] controls) {
        if (controls != null) {
            for (Control control : controls) {
                if (control instanceof PagedResultsResponseControl) {
                    PagedResultsResponseControl pagedControl =
                    return pagedControl.getCookie();
        return null;
New to GrepCode? Check out our FAQ X