モジュール java.naming
パッケージ javax.naming.ldap

クラスSortControl

java.lang.Object
javax.naming.ldap.BasicControl
javax.naming.ldap.SortControl
すべての実装されたインタフェース:
Serializable, Control

public final class SortControl extends BasicControl
検索操作の結果をソートしてから返すようにLDAPサーバーに要求します。 ソート条件は、1つ以上のソート・キーとそのソート・パラメータを順に並べたリストで指定します。 検索結果は、ソート・コントロールで指定されたパラメータに従ってLDAPサーバーでソートされ、要求者に返されます。 サーバーがソート機能をサポートしていない場合、ソート・コントロールがクリティカルとマークされているときは、検索操作は実行されず、エラーが返されます。

このクラスの使用方法を示すコーディング例を次に示します。



     // Open an LDAP association
     LdapContext ctx = new InitialLdapContext();

     // Activate sorting
     String sortKey = "cn";
     ctx.setRequestControls(new Control[]{
         new SortControl(sortKey, Control.CRITICAL) });

     // Perform a search
     NamingEnumeration results =
         ctx.search("", "(objectclass=*)", new SearchControls());

     // Iterate over search results
     while (results != null && results.hasMore()) {
         // Display an entry
         SearchResult entry = (SearchResult)results.next();
         System.out.println(entry.getName());
         System.out.println(entry.getAttributes());

         // Handle the entry's response controls (if any)
         if (entry instanceof HasControls) {
             // ((HasControls)entry).getControls();
         }
     }
     // Examine the sort control response
     Control[] controls = ctx.getResponseControls();
     if (controls != null) {
         for (int i = 0; i < controls.length; i++) {
             if (controls[i] instanceof SortResponseControl) {
                 SortResponseControl src = (SortResponseControl)controls[i];
                 if (! src.isSorted()) {
                     throw src.getException();
                 }
             } else {
                 // Handle other response controls (if any)
             }
         }
     }

     // Close the LDAP association
     ctx.close();
     ...

 

このクラスは、RFC 2891で定義されているサーバー側でのソートのLDAPv3要求コントロールを実装します。 このコントロールの値のASN.1定義は次のとおりです。


     SortKeyList ::= SEQUENCE OF SEQUENCE {
         attributeType     AttributeDescription,
         orderingRule  [0] MatchingRuleId OPTIONAL,
         reverseOrder  [1] BOOLEAN DEFAULT FALSE }

 

導入されたバージョン:
1.5
関連項目: