IntermediateResponseProtocolOp.java revision f71f7a61dec7c9089378d14493ad564a1dedf0b5
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * CDDL HEADER START
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms of the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Common Development and Distribution License, Version 1.0 only
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the "License"). You may not use this file except in compliance
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the license at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * trunk/opends/resource/legal-notices/OpenDS.LICENSE
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing permissions
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL HEADER in each
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * file and include the License file at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * add the following below this CDDL HEADER, with the fields enclosed
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * by brackets "[]" replaced with your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Portions Copyright [yyyy] [name of copyright owner]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * CDDL HEADER END
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Portions Copyright 2006-2007 Sun Microsystems, Inc.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport org.opends.server.protocols.asn1.ASN1Element;
80849398a45dca1fb917716907d6ec99be6222c2Peter Majorimport org.opends.server.protocols.asn1.ASN1Exception;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport org.opends.server.protocols.asn1.ASN1OctetString;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport org.opends.server.protocols.asn1.ASN1Sequence;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport static org.opends.server.loggers.debug.DebugLogger.debugCought;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport static org.opends.server.loggers.debug.DebugLogger.debugEnabled;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport static org.opends.server.messages.MessageHandler.*;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport static org.opends.server.messages.ProtocolMessages.*;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport static org.opends.server.protocols.ldap.LDAPConstants.*;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport static org.opends.server.protocols.ldap.LDAPResultCode.*;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport static org.opends.server.util.ServerConstants.*;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport static org.opends.server.util.StaticUtils.*;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This class defines the structures and methods for an LDAP intermediate
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * response protocol op, which is used to provide information to a client before
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the final response for an operation.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The value for this intermediate response.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The OID for this intermediate response.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Creates a new intermediate protocol op with the specified OID and no
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param oid The OID for this intermediate response.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public IntermediateResponseProtocolOp(String oid)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Creates a new intermediate response protocol op with the specified OID and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param oid The OID for this intermediate response.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param value The value for this intermediate response.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public IntermediateResponseProtocolOp(String oid, ASN1OctetString value)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Retrieves the OID for this intermediate response.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return The OID for this intermediate response, or <CODE>null</CODE> if
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * there is no OID.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Specifies the OID for this intermediate response.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param oid The OID for this intermediate response.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Retrieves the value for this intermediate response.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return The value for this intermediate response, or <CODE>null</CODE> if
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * there is no value.
f92849012ac6d84ddaad627d1c96f021d06998ecjeff.schenk * Specifies the value for this intermediate response.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param value The value for this intermediate response.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Retrieves the BER type for this protocol op.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return The BER type for this protocol op.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public byte getType()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Retrieves the name for this protocol op type.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return The name for this protocol op type.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return "Intermediate Response";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Encodes this protocol op to an ASN.1 element suitable for including in an
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * LDAP message.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return The ASN.1 element containing the encoded protocol op.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ArrayList<ASN1Element> elements = new ArrayList<ASN1Element>(2);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster elements.add(new ASN1OctetString(TYPE_INTERMEDIATE_RESPONSE_OID, oid));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster value.setType(TYPE_INTERMEDIATE_RESPONSE_VALUE);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return new ASN1Sequence(OP_TYPE_INTERMEDIATE_RESPONSE, elements);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Decodes the provided ASN.1 element as an LDAP intermediate response
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * protocol op.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param element The ASN.1 element to be decoded.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return The decoded intermediate response protocol op.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws LDAPException If a problem occurs while attempting to decode the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * provided ASN.1 element as an LDAP intermediate
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * response protocol op.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster decodeIntermediateResponse(ASN1Element element)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster elements = element.decodeAsSequence().elements();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int msgID = MSGID_LDAP_INTERMEDIATE_RESPONSE_DECODE_SEQUENCE;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String message = getMessage(msgID, String.valueOf(e));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new LDAPException(PROTOCOL_ERROR, msgID, message, e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int msgID = MSGID_LDAP_INTERMEDIATE_RESPONSE_DECODE_INVALID_ELEMENT_COUNT;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String message = getMessage(msgID, numElements);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new LDAPException(PROTOCOL_ERROR, msgID, message);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int msgID = MSGID_LDAP_INTERMEDIATE_RESPONSE_CANNOT_DECODE_OID;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String message = getMessage(msgID, ae.getMessage());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new LDAPException(PROTOCOL_ERROR, msgID, message);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int msgID = MSGID_LDAP_INTERMEDIATE_RESPONSE_CANNOT_DECODE_VALUE;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String message = getMessage(msgID, ae.getMessage());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new LDAPException(PROTOCOL_ERROR, msgID, message);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int msgID = MSGID_LDAP_INTERMEDIATE_RESPONSE_INVALID_ELEMENT_TYPE;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String message = getMessage(msgID, byteToHex(e.getType()));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new LDAPException(PROTOCOL_ERROR, msgID, message);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster oid = elements.get(0).decodeAsOctetString().stringValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int msgID = MSGID_LDAP_INTERMEDIATE_RESPONSE_CANNOT_DECODE_OID;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String message = getMessage(msgID, ae.getMessage());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new LDAPException(PROTOCOL_ERROR, msgID, message);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int msgID = MSGID_LDAP_INTERMEDIATE_RESPONSE_CANNOT_DECODE_OID;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String message = getMessage(msgID, ae.getMessage());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new LDAPException(PROTOCOL_ERROR, msgID, message);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return new IntermediateResponseProtocolOp(oid, value);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Appends a string representation of this LDAP protocol op to the provided
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param buffer The buffer to which the string should be appended.
751ffbacd21180fbc0849885f30c91425fcee44ajeff.schenk * Appends a multi-line string representation of this LDAP protocol op to the
751ffbacd21180fbc0849885f30c91425fcee44ajeff.schenk * provided buffer.
751ffbacd21180fbc0849885f30c91425fcee44ajeff.schenk * @param buffer The buffer to which the information should be appended.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param indent The number of spaces from the margin that the lines should
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * be indented.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void toString(StringBuilder buffer, int indent)