Package javax.naming.directory

Examples of javax.naming.directory.SearchControls


    this.parser = new IQueryToLdapSearchParser(this.executionFactory);
    searchDetails = parser.translateSQLQueryToLDAPSearch(query);

    // Create and configure the new search context.
    createSearchContext();
    SearchControls ctrls = setSearchControls();
    setStandardRequestControls();
    // Execute the search.
    executeSearch(ctrls);
  }
View Full Code Here


  /**
   * Set the search controls
   */
  private SearchControls setSearchControls() {
    SearchControls ctrls = new SearchControls();
    //ArrayList modelAttrList = searchDetails.getAttributeList();
    ArrayList<Column> modelAttrList = searchDetails.getElementList();
    String[] attrs = new String[modelAttrList.size()];
    for (int i = 0; i < attrs.length; i++) {
      attrs[i] = (parser.getNameFromElement(modelAttrList.get(i)));
    }

    ctrls.setSearchScope(searchDetails.getSearchScope());
    ctrls.setReturningAttributes(attrs);
   
    long limit = searchDetails.getCountLimit();
    if(limit != -1) {
      ctrls.setCountLimit(limit);
    }
    return ctrls;
  }
View Full Code Here

     * Execute the given LDAP requests
     */
    Vector requests = extractRequests((Document) callData);
    NamingEnumeration results = null;
    DirContext context = connection.getContext();
    SearchControls controls = connection.getSearchControls();

    for (Iterator it = requests.iterator(); it.hasNext();)
    {
      RequestContainer request = (RequestContainer) it.next();
      String requestType = request.getType();
View Full Code Here

    if (timelim < 0)
    {
      timelim = 0;
    }

    SearchControls controls = new SearchControls();
    controls.setSearchScope(scope);
    controls.setCountLimit(countlim);
    controls.setCountLimit(timelim);

    return controls;
  }
View Full Code Here

      sr.setNameInNamespace(uriToName(baseURI));
      results = new SingletonNamingEnumeration<SearchResult>(sr);
    }
    else // An actual query
    {
      SearchControls sc = new SearchControls();
      sc.setReturningAttributes(toGet.toArray(new String[] {}));
      sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
     
      results = context.search(baseURI, queryString, sc);
    }

    return results;
View Full Code Here

  }
 
  /* As above, best ignored */
  public void notest1() throws NamingException
  {
    SearchControls sc = new SearchControls();
    sc.setDerefLinkFlag(true);
    //sc.setReturningAttributes(new String[]{"sn","cn","manager"});
    sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
    NamingEnumeration<SearchResult> results = context.search(directory + "o=hp.com", "(cn=*shabajee*)", sc);
   
    assertTrue("I found Paul", results.hasMore());
   
    while (results.hasMore())
View Full Code Here

        this.ouSearchBase = ouSearchBase;
        this.pageSize = pageSize;
    }

    boolean searchForResult(InitialLdapContext context, String searchBase, String filter) throws NamingException {
        SearchControls constraints = new SearchControls();
        constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
        NamingEnumeration<SearchResult> results = context.search(searchBase, filter, constraints);
        return results.hasMore();
    }
View Full Code Here

        }
    }

    private void doSearch(InitialLdapContext context, String filter, String[] attributes, PagedResultMapper mapper)
                    throws NamingException {
        SearchControls constraints = new SearchControls();
        constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);

        for (String searchBase : ouSearchBase) {
            if (logger.isDebugEnabled()) {
                logger.debug("Looking for items starting at " + searchBase + " (filter = " + filter + ")");
            }

            try {
                constraints.setReturningAttributes(attributes);
                NamingEnumeration<SearchResult> results = context.search(searchBase, filter, constraints);
                mapResults(mapper, results);
            } catch (PartialResultException e) {
                // ignore
            } catch (NamingException e) {
View Full Code Here

        }
    }

    private void doPagedSearch(InitialLdapContext context, String filter, String[] attributes, PagedResultMapper mapper)
                    throws NamingException {
        SearchControls constraints = new SearchControls();
        constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
        applyControls(context, pageSize);

        for (String searchBase : ouSearchBase) {
            if (logger.isDebugEnabled()) {
                logger.debug("Looking for items starting at " + searchBase + " (filter = " + filter + ")");
            }

            try {
                int currentPage = 1;
                int startPosition = 0;
                int endPosition = pageSize - 1;
                byte[] cookie = null;
       
                do {
                    String range = startPosition + "-" + endPosition;

                    if (logger.isDebugEnabled()) {
                        logger.debug("Starting search on page " + currentPage + " " + range);
                    }

                    constraints.setReturningAttributes(attributes);
                    NamingEnumeration<SearchResult> results = context.search(searchBase, filter, constraints);

                    try {
                        mapResults(mapper, results);
                    } catch (PartialResultException pre) {
View Full Code Here

  /// <dt><code>sequence</code></dt>
  /// <dd>Sequence of name of attributes to return</dd>
  /// </dl>
  public static final Any newInstance(anvil.script.Context context, Any[] parameters)
  {
    SearchControls controls = new SearchControls();
    int n = parameters.length;
    for(int i=0; i<n; i++) {
      Any property = parameters[i];
      if (property.isMap()) {
        AnyMap map = property.toMap();
        String key = map.getLeft().toString();
        if (key.equalsIgnoreCase("scope")) {
          controls.setSearchScope(map.getRight().toInt());
        } else if (key.equalsIgnoreCase("countlimit")) {
          controls.setCountLimit(map.getRight().toInt());
        } else if (key.equalsIgnoreCase("timelimit")) {
          controls.setTimeLimit(map.getRight().toInt());
        } else if (key.equalsIgnoreCase("attributes")) {
          Any right = map.getRight();
          if (right.isNull()) {
            controls.setReturningAttributes(null);
          } else {
            String[] attributes = AnyUtils.toStringArray(right);
            controls.setReturningAttributes(attributes);
          }
        } else if (key.equalsIgnoreCase("returnobject")) {
          controls.setReturningObjFlag(map.getRight().toBoolean());
        } else if (key.equalsIgnoreCase("dereflinks")) {
          controls.setDerefLinkFlag(map.getRight().toBoolean());
        } else {
          throw context.BadParameter("Invalid attribute: '"+key+"'");
        }
       
      } else if (property.isString()) {
        String key = property.toString();
        if (key.equalsIgnoreCase("returnobject")) {
          controls.setReturningObjFlag(true);
        } else if (key.equalsIgnoreCase("dereflinks")) {
          controls.setDerefLinkFlag(true);
        } else {
          throw context.BadParameter("Invalid attribute: '"+key+"'");
        }

      } else if (property.isSequence() || property.isArray()) {
        String[] attributes = AnyUtils.toStringArray(property);
        controls.setReturningAttributes(attributes);
       
      } else {
        throw context.BadParameter("Invalid property: '"+property+"'");
      }
     
View Full Code Here

TOP

Related Classes of javax.naming.directory.SearchControls

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.