KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > naming > ldap > SortResponseControl


1 /*
2  * @(#)SortResponseControl.java 1.3 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.naming.ldap;
9
10 import java.io.IOException JavaDoc;
11 import javax.naming.*;
12 import javax.naming.directory.*;
13 import com.sun.jndi.ldap.Ber;
14 import com.sun.jndi.ldap.BerDecoder;
15 import com.sun.jndi.ldap.LdapCtx;
16
17 /**
18  * Indicates whether the requested sort of search results was successful or not.
19  * When the result code indicates success then the results have been sorted as
20  * requested. Otherwise the sort was unsuccessful and additional details
21  * regarding the cause of the error may have been provided by the server.
22  * <p>
23  * The code sample in {@link SortControl} shows how this class may be used.
24  * <p>
25  * This class implements the LDAPv3 Response Control for server-side sorting
26  * as defined in
27  * <a HREF="http://www.ietf.org/rfc/rfc2891.txt">RFC 2891</a>.
28  *
29  * The control's value has the following ASN.1 definition:
30  * <pre>
31  *
32  * SortResult ::= SEQUENCE {
33  * sortResult ENUMERATED {
34  * success (0), -- results are sorted
35  * operationsError (1), -- server internal failure
36  * timeLimitExceeded (3), -- timelimit reached before
37  * -- sorting was completed
38  * strongAuthRequired (8), -- refused to return sorted
39  * -- results via insecure
40  * -- protocol
41  * adminLimitExceeded (11), -- too many matching entries
42  * -- for the server to sort
43  * noSuchAttribute (16), -- unrecognized attribute
44  * -- type in sort key
45  * inappropriateMatching (18), -- unrecognized or inappro-
46  * -- priate matching rule in
47  * -- sort key
48  * insufficientAccessRights (50), -- refused to return sorted
49  * -- results to this client
50  * busy (51), -- too busy to process
51  * unwillingToPerform (53), -- unable to sort
52  * other (80)
53  * },
54  * attributeType [0] AttributeType OPTIONAL }
55  *
56  * </pre>
57  *
58  * @since 1.5
59  * @see SortControl
60  * @author Vincent Ryan
61  */

62 final public class SortResponseControl extends BasicControl JavaDoc {
63
64     /**
65      * The server-side sort response control's assigned object identifier
66      * is 1.2.840.113556.1.4.474.
67      */

68     public static final String JavaDoc OID = "1.2.840.113556.1.4.474";
69
70     private static final long serialVersionUID = 5142939176006310877L;
71
72     /**
73      * The sort result code.
74      *
75      * @serial
76      */

77     private int resultCode = 0;
78
79     /**
80      * The ID of the attribute that caused the sort to fail.
81      *
82      * @serial
83      */

84     private String JavaDoc badAttrId = null;
85
86     /**
87      * Constructs a control to indicate the outcome of a sort request.
88      *
89      * @param id The control's object identifier string.
90      * @param criticality The control's criticality.
91      * @param value The control's ASN.1 BER encoded value.
92      * It is not cloned - any changes to value
93      * will affect the contents of the control.
94      * @exception IOException if an error is encountered
95      * while decoding the control's value.
96      */

97     public SortResponseControl(String JavaDoc id, boolean criticality, byte[] value)
98     throws IOException JavaDoc {
99
100     super(id, criticality, value);
101
102     // decode value
103
BerDecoder ber = new BerDecoder(value, 0, value.length);
104
105     ber.parseSeq(null);
106     resultCode = ber.parseEnumeration();
107     if ((ber.bytesLeft() > 0) && (ber.peekByte() == Ber.ASN_CONTEXT)) {
108         badAttrId = ber.parseStringWithTag(Ber.ASN_CONTEXT, true, null);
109     }
110     }
111
112     /**
113      * Determines if the search results have been successfully sorted.
114      * If an error occurred during sorting a NamingException is thrown.
115      *
116      * @return true if the search results have been sorted.
117      */

118     public boolean isSorted() {
119     return (resultCode == 0); // a result code of zero indicates success
120
}
121
122     /**
123      * Retrieves the LDAP result code of the sort operation.
124      *
125      * @return The result code. A zero value indicates success.
126      */

127     public int getResultCode() {
128     return resultCode;
129     }
130
131     /**
132      * Retrieves the ID of the attribute that caused the sort to fail.
133      * Returns null if no ID was returned by the server.
134      *
135      * @return The possibly null ID of the bad attribute.
136      */

137     public String JavaDoc getAttributeID() {
138     return badAttrId;
139     }
140
141     /**
142      * Retrieves the NamingException appropriate for the result code.
143      *
144      * @return A NamingException or null if the result code indicates
145      * success.
146      */

147     public NamingException getException() {
148
149     return LdapCtx.mapErrorCode(resultCode, null);
150     }
151 }
152
Popular Tags