171 * The list is in order of highest to lowest sort key
172 * precedence.
173 * @param criticality If true then the server must honor the control
174 * and return the search results sorted as
175 * requested or refuse to perform the search.
176 * If false, then the server need not honor the
177 * control.
178 * @exception IOException If an error was encountered while encoding the
179 * supplied arguments into a control.
180 */
181 public SortControl(SortKey[] sortBy, boolean criticality)
182 throws IOException {
183
184 super(OID, criticality, null);
185 super.value = setEncodedValue(sortBy);
186 }
187
188 /*
189 * Encodes the sort control's value using ASN.1 BER.
190 * The result includes the BER tag and length for the control's value but
191 * does not include the control's object identifer and criticality setting.
192 *
193 * @param sortKeys A non-null list of keys to sort by.
194 * @return A possibly null byte array representing the ASN.1 BER encoded
195 * value of the sort control.
196 * @exception IOException If a BER encoding error occurs.
197 */
198 private byte[] setEncodedValue(SortKey[] sortKeys) throws IOException {
199
200 // build the ASN.1 BER encoding
201 BerEncoder ber = new BerEncoder(30 * sortKeys.length + 10);
202 String matchingRule;
203
204 ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
205
206 for (int i = 0; i < sortKeys.length; i++) {
207 ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
208 ber.encodeString(sortKeys[i].getAttributeID(), true); // v3
209
210 if ((matchingRule = sortKeys[i].getMatchingRuleID()) != null) {
211 ber.encodeString(matchingRule, (Ber.ASN_CONTEXT | 0), true);
|
171 * The list is in order of highest to lowest sort key
172 * precedence.
173 * @param criticality If true then the server must honor the control
174 * and return the search results sorted as
175 * requested or refuse to perform the search.
176 * If false, then the server need not honor the
177 * control.
178 * @exception IOException If an error was encountered while encoding the
179 * supplied arguments into a control.
180 */
181 public SortControl(SortKey[] sortBy, boolean criticality)
182 throws IOException {
183
184 super(OID, criticality, null);
185 super.value = setEncodedValue(sortBy);
186 }
187
188 /*
189 * Encodes the sort control's value using ASN.1 BER.
190 * The result includes the BER tag and length for the control's value but
191 * does not include the control's object identifier and criticality setting.
192 *
193 * @param sortKeys A non-null list of keys to sort by.
194 * @return A possibly null byte array representing the ASN.1 BER encoded
195 * value of the sort control.
196 * @exception IOException If a BER encoding error occurs.
197 */
198 private byte[] setEncodedValue(SortKey[] sortKeys) throws IOException {
199
200 // build the ASN.1 BER encoding
201 BerEncoder ber = new BerEncoder(30 * sortKeys.length + 10);
202 String matchingRule;
203
204 ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
205
206 for (int i = 0; i < sortKeys.length; i++) {
207 ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
208 ber.encodeString(sortKeys[i].getAttributeID(), true); // v3
209
210 if ((matchingRule = sortKeys[i].getMatchingRuleID()) != null) {
211 ber.encodeString(matchingRule, (Ber.ASN_CONTEXT | 0), true);
|