From 22094368c2865dcfb6daf8366425212b721a4657 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Thu, 05 Feb 2009 17:42:14 +0000
Subject: [PATCH] Merge ASN1 branch to trunk
---
opends/src/server/org/opends/server/protocols/ldap/ModifyDNResponseProtocolOp.java | 246 ++++--------------------------------------------
1 files changed, 23 insertions(+), 223 deletions(-)
diff --git a/opends/src/server/org/opends/server/protocols/ldap/ModifyDNResponseProtocolOp.java b/opends/src/server/org/opends/server/protocols/ldap/ModifyDNResponseProtocolOp.java
index 97b71b7..19b7e3d 100644
--- a/opends/src/server/org/opends/server/protocols/ldap/ModifyDNResponseProtocolOp.java
+++ b/opends/src/server/org/opends/server/protocols/ldap/ModifyDNResponseProtocolOp.java
@@ -28,24 +28,16 @@
import org.opends.messages.Message;
-
-import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.io.IOException;
-import org.opends.server.protocols.asn1.ASN1Element;
-import org.opends.server.protocols.asn1.ASN1Enumerated;
-import org.opends.server.protocols.asn1.ASN1OctetString;
-import org.opends.server.protocols.asn1.ASN1Sequence;
-import org.opends.server.types.DebugLogLevel;
+import org.opends.server.protocols.asn1.*;
import org.opends.server.types.DN;
-import org.opends.server.types.LDAPException;
import static org.opends.server.loggers.debug.DebugLogger.*;
import org.opends.server.loggers.debug.DebugTracer;
-import static org.opends.messages.ProtocolMessages.*;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
-import static org.opends.server.protocols.ldap.LDAPResultCode.*;
import static org.opends.server.util.ServerConstants.*;
@@ -141,19 +133,6 @@
}
-
- /**
- * Specifies the result code for this response.
- *
- * @param resultCode The result code for this response.
- */
- public void setResultCode(int resultCode)
- {
- this.resultCode = resultCode;
- }
-
-
-
/**
* Retrieves the error message for this response.
*
@@ -168,18 +147,6 @@
/**
- * Specifies the error message for this response.
- *
- * @param errorMessage The error message for this response.
- */
- public void setErrorMessage(Message errorMessage)
- {
- this.errorMessage = errorMessage;
- }
-
-
-
- /**
* Retrieves the matched DN for this response.
*
* @return The matched DN for this response, or <CODE>null</CODE> if none is
@@ -193,18 +160,6 @@
/**
- * Specifies the matched DN for this response.
- *
- * @param matchedDN The matched DN for this response.
- */
- public void setMatchedDN(DN matchedDN)
- {
- this.matchedDN = matchedDN;
- }
-
-
-
- /**
* Retrieves the set of referral URLs for this response.
*
* @return The set of referral URLs for this response, or <CODE>null</CODE>
@@ -218,18 +173,6 @@
/**
- * Specifies the set of referral URLs for this response.
- *
- * @param referralURLs The set of referral URLs for this response.
- */
- public void setReferralURLs(List<String> referralURLs)
- {
- this.referralURLs = referralURLs;
- }
-
-
-
- /**
* Retrieves the BER type for this protocol op.
*
* @return The BER type for this protocol op.
@@ -251,189 +194,46 @@
return "Modify DN Response";
}
-
-
/**
- * Encodes this protocol op to an ASN.1 element suitable for including in an
- * LDAP message.
+ * Writes this protocol op to an ASN.1 output stream.
*
- * @return The ASN.1 element containing the encoded protocol op.
+ * @param stream The ASN.1 output stream to write to.
+ * @throws IOException If a problem occurs while writing to the stream.
*/
- public ASN1Element encode()
+ public void write(ASN1Writer stream) throws IOException
{
- ArrayList<ASN1Element> elements = new ArrayList<ASN1Element>(4);
- elements.add(new ASN1Enumerated(resultCode));
+ stream.writeStartSequence(OP_TYPE_MODIFY_DN_RESPONSE);
+ stream.writeEnumerated(resultCode);
- if (matchedDN == null)
+ if(matchedDN == null)
{
- elements.add(new ASN1OctetString());
+ stream.writeOctetString((String)null);
}
else
{
- elements.add(new ASN1OctetString(matchedDN.toString()));
+ stream.writeOctetString(matchedDN.toString());
}
- elements.add(new ASN1OctetString(errorMessage));
+ if(errorMessage == null)
+ {
+ stream.writeOctetString((String)null);
+ }
+ else
+ {
+ stream.writeOctetString(errorMessage.toString());
+ }
if ((referralURLs != null) && (! referralURLs.isEmpty()))
{
- ArrayList<ASN1Element> referralElements =
- new ArrayList<ASN1Element>(referralURLs.size());
-
+ stream.writeStartSequence(TYPE_REFERRAL_SEQUENCE);
for (String s : referralURLs)
{
- referralElements.add(new ASN1OctetString(s));
+ stream.writeOctetString(s);
}
-
- elements.add(new ASN1Sequence(TYPE_REFERRAL_SEQUENCE, referralElements));
+ stream.writeEndSequence();
}
- return new ASN1Sequence(OP_TYPE_MODIFY_DN_RESPONSE, elements);
- }
-
-
-
- /**
- * Decodes the provided ASN.1 element as a modify DN response protocol op.
- *
- * @param element The ASN.1 element to decode.
- *
- * @return The decoded modify DN response protocol op.
- *
- * @throws LDAPException If a problem occurs while attempting to decode the
- * ASN.1 element to a protocol op.
- */
- public static ModifyDNResponseProtocolOp decodeModifyDNResponse(ASN1Element
- element)
- throws LDAPException
- {
- ArrayList<ASN1Element> elements;
- try
- {
- elements = element.decodeAsSequence().elements();
- }
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
-
- Message message = ERR_LDAP_RESULT_DECODE_SEQUENCE.get(String.valueOf(e));
- throw new LDAPException(PROTOCOL_ERROR, message, e);
- }
-
-
- int numElements = elements.size();
- if ((numElements < 3) || (numElements > 4))
- {
- Message message =
- ERR_LDAP_RESULT_DECODE_INVALID_ELEMENT_COUNT.get(numElements);
- throw new LDAPException(PROTOCOL_ERROR, message);
- }
-
-
- int resultCode;
- try
- {
- resultCode = elements.get(0).decodeAsInteger().intValue();
- }
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
-
- Message message =
- ERR_LDAP_RESULT_DECODE_RESULT_CODE.get(String.valueOf(e));
- throw new LDAPException(PROTOCOL_ERROR, message, e);
- }
-
-
- DN matchedDN;
- try
- {
- String dnString = elements.get(1).decodeAsOctetString().stringValue();
- if (dnString.length() == 0)
- {
- matchedDN = null;
- }
- else
- {
- matchedDN = DN.decode(dnString);
- }
- }
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
-
- Message message =
- ERR_LDAP_RESULT_DECODE_MATCHED_DN.get(String.valueOf(e));
- throw new LDAPException(PROTOCOL_ERROR, message, e);
- }
-
-
- Message errorMessage;
- try
- {
- errorMessage = Message.raw(
- elements.get(2).decodeAsOctetString().stringValue());
- if (errorMessage.length() == 0)
- {
- errorMessage = null;
- }
- }
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
-
- Message message =
- ERR_LDAP_RESULT_DECODE_ERROR_MESSAGE.get(String.valueOf(e));
- throw new LDAPException(PROTOCOL_ERROR, message, e);
- }
-
-
- ArrayList<String> referralURLs;
- if (numElements == 3)
- {
- referralURLs = null;
- }
- else
- {
- try
- {
- ArrayList<ASN1Element> referralElements =
- elements.get(3).decodeAsSequence().elements();
- referralURLs = new ArrayList<String>(referralElements.size());
-
- for (ASN1Element e : referralElements)
- {
- referralURLs.add(e.decodeAsOctetString().stringValue());
- }
- }
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
-
- Message message =
- ERR_LDAP_RESULT_DECODE_REFERRALS.get(String.valueOf(e));
- throw new LDAPException(PROTOCOL_ERROR, message, e);
- }
- }
-
-
- return new ModifyDNResponseProtocolOp(resultCode, errorMessage, matchedDN,
- referralURLs);
+ stream.writeEndSequence();
}
--
Gitblit v1.10.0