0N/A/*
2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.naming.ldap;
0N/A
0N/Aimport java.io.IOException;
0N/Aimport javax.naming.*;
0N/Aimport javax.naming.directory.*;
0N/Aimport com.sun.jndi.ldap.Ber;
0N/Aimport com.sun.jndi.ldap.BerDecoder;
0N/Aimport com.sun.jndi.ldap.LdapCtx;
0N/A
0N/A/**
0N/A * Indicates whether the requested sort of search results was successful or not.
0N/A * When the result code indicates success then the results have been sorted as
0N/A * requested. Otherwise the sort was unsuccessful and additional details
0N/A * regarding the cause of the error may have been provided by the server.
0N/A * <p>
0N/A * The code sample in {@link SortControl} shows how this class may be used.
0N/A * <p>
0N/A * This class implements the LDAPv3 Response Control for server-side sorting
0N/A * as defined in
0N/A * <a href="http://www.ietf.org/rfc/rfc2891.txt">RFC 2891</a>.
0N/A *
0N/A * The control's value has the following ASN.1 definition:
0N/A * <pre>
0N/A *
0N/A * SortResult ::= SEQUENCE {
0N/A * sortResult ENUMERATED {
0N/A * success (0), -- results are sorted
0N/A * operationsError (1), -- server internal failure
0N/A * timeLimitExceeded (3), -- timelimit reached before
0N/A * -- sorting was completed
0N/A * strongAuthRequired (8), -- refused to return sorted
0N/A * -- results via insecure
0N/A * -- protocol
0N/A * adminLimitExceeded (11), -- too many matching entries
0N/A * -- for the server to sort
0N/A * noSuchAttribute (16), -- unrecognized attribute
0N/A * -- type in sort key
0N/A * inappropriateMatching (18), -- unrecognized or inappro-
0N/A * -- priate matching rule in
0N/A * -- sort key
0N/A * insufficientAccessRights (50), -- refused to return sorted
0N/A * -- results to this client
0N/A * busy (51), -- too busy to process
0N/A * unwillingToPerform (53), -- unable to sort
0N/A * other (80)
0N/A * },
0N/A * attributeType [0] AttributeType OPTIONAL }
0N/A *
0N/A * </pre>
0N/A *
0N/A * @since 1.5
0N/A * @see SortControl
0N/A * @author Vincent Ryan
0N/A */
0N/Afinal public class SortResponseControl extends BasicControl {
0N/A
0N/A /**
0N/A * The server-side sort response control's assigned object identifier
0N/A * is 1.2.840.113556.1.4.474.
0N/A */
0N/A public static final String OID = "1.2.840.113556.1.4.474";
0N/A
0N/A private static final long serialVersionUID = 5142939176006310877L;
0N/A
0N/A /**
0N/A * The sort result code.
0N/A *
0N/A * @serial
0N/A */
0N/A private int resultCode = 0;
0N/A
0N/A /**
0N/A * The ID of the attribute that caused the sort to fail.
0N/A *
0N/A * @serial
0N/A */
0N/A private String badAttrId = null;
0N/A
0N/A /**
0N/A * Constructs a control to indicate the outcome of a sort request.
0N/A *
0N/A * @param id The control's object identifier string.
0N/A * @param criticality The control's criticality.
0N/A * @param value The control's ASN.1 BER encoded value.
0N/A * It is not cloned - any changes to value
0N/A * will affect the contents of the control.
0N/A * @exception IOException if an error is encountered
0N/A * while decoding the control's value.
0N/A */
0N/A public SortResponseControl(String id, boolean criticality, byte[] value)
0N/A throws IOException {
0N/A
0N/A super(id, criticality, value);
0N/A
0N/A // decode value
0N/A BerDecoder ber = new BerDecoder(value, 0, value.length);
0N/A
0N/A ber.parseSeq(null);
0N/A resultCode = ber.parseEnumeration();
0N/A if ((ber.bytesLeft() > 0) && (ber.peekByte() == Ber.ASN_CONTEXT)) {
0N/A badAttrId = ber.parseStringWithTag(Ber.ASN_CONTEXT, true, null);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Determines if the search results have been successfully sorted.
0N/A * If an error occurred during sorting a NamingException is thrown.
0N/A *
0N/A * @return true if the search results have been sorted.
0N/A */
0N/A public boolean isSorted() {
0N/A return (resultCode == 0); // a result code of zero indicates success
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the LDAP result code of the sort operation.
0N/A *
0N/A * @return The result code. A zero value indicates success.
0N/A */
0N/A public int getResultCode() {
0N/A return resultCode;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the ID of the attribute that caused the sort to fail.
0N/A * Returns null if no ID was returned by the server.
0N/A *
0N/A * @return The possibly null ID of the bad attribute.
0N/A */
0N/A public String getAttributeID() {
0N/A return badAttrId;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the NamingException appropriate for the result code.
0N/A *
0N/A * @return A NamingException or null if the result code indicates
0N/A * success.
0N/A */
0N/A public NamingException getException() {
0N/A
0N/A return LdapCtx.mapErrorCode(resultCode, null);
0N/A }
0N/A}