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/controls/PasswordPolicyRequestControl.java |   92 +++++++++++++++++++++++++---------------------
 1 files changed, 50 insertions(+), 42 deletions(-)

diff --git a/opends/src/server/org/opends/server/controls/PasswordPolicyRequestControl.java b/opends/src/server/org/opends/server/controls/PasswordPolicyRequestControl.java
index 79b2728..fd8b54e 100644
--- a/opends/src/server/org/opends/server/controls/PasswordPolicyRequestControl.java
+++ b/opends/src/server/org/opends/server/controls/PasswordPolicyRequestControl.java
@@ -29,13 +29,16 @@
 
 
 
-import org.opends.server.protocols.ldap.LDAPResultCode;
+import org.opends.server.protocols.asn1.ASN1Writer;
+import org.opends.server.types.ByteString;
 import org.opends.server.types.Control;
-import org.opends.server.types.LDAPException;
+import org.opends.server.types.DirectoryException;
+import org.opends.server.types.ResultCode;
 
 import static org.opends.messages.ProtocolMessages.*;
 import static org.opends.server.util.ServerConstants.*;
 
+import java.io.IOException;
 
 
 /**
@@ -45,8 +48,42 @@
 public class PasswordPolicyRequestControl
        extends Control
 {
+  /**
+   * ControlDecoder implentation to decode this control from a ByteString.
+   */
+  private final static class Decoder
+      implements ControlDecoder<PasswordPolicyRequestControl>
+  {
+    /**
+     * {@inheritDoc}
+     */
+    public PasswordPolicyRequestControl decode(boolean isCritical,
+                                               ByteString value)
+        throws DirectoryException
+    {
+      if (value != null)
+      {
+        Message message = ERR_PWPOLICYREQ_CONTROL_HAS_VALUE.get();
+        throw new DirectoryException(ResultCode.PROTOCOL_ERROR, message);
+      }
 
 
+      return new PasswordPolicyRequestControl(isCritical);
+    }
+
+    public String getOID()
+    {
+      return OID_PASSWORD_POLICY_CONTROL;
+    }
+
+  }
+
+  /**
+   * The Control Decoder that can be used to decode this control.
+   */
+  public static final ControlDecoder<PasswordPolicyRequestControl> DECODER =
+    new Decoder();
+
 
   /**
    * Creates a new instance of the password policy request control with the
@@ -54,7 +91,7 @@
    */
   public PasswordPolicyRequestControl()
   {
-    super(OID_PASSWORD_POLICY_CONTROL, false);
+    this(false);
 
   }
 
@@ -64,57 +101,27 @@
    * Creates a new instance of the password policy request control with the
    * provided information.
    *
-   * @param  oid         The OID to use for this control.
    * @param  isCritical  Indicates whether support for this control should be
    *                     considered a critical part of the client processing.
    */
-  public PasswordPolicyRequestControl(String oid, boolean isCritical)
+  public PasswordPolicyRequestControl(boolean isCritical)
   {
-    super(oid, isCritical);
+    super(OID_PASSWORD_POLICY_CONTROL, isCritical);
 
   }
 
 
 
   /**
-   * Creates a new password policy request control from the contents of the
-   * provided control.
+   * Writes this control's value to an ASN.1 writer. The value (if any) must be
+   * written as an ASN1OctetString.
    *
-   * @param  control  The generic control containing the information to use to
-   *                  create this password policy request control.
-   *
-   * @return  The password policy request control decoded from the provided
-   *          control.
-   *
-   * @throws  LDAPException  If this control cannot be decoded as a valid
-   *                         password policy request control.
+   * @param writer The ASN.1 output stream to write to.
+   * @throws IOException If a problem occurs while writing to the stream.
    */
-  public static PasswordPolicyRequestControl decodeControl(Control control)
-         throws LDAPException
-  {
-    if (control.hasValue())
-    {
-      Message message = ERR_PWPOLICYREQ_CONTROL_HAS_VALUE.get();
-      throw new LDAPException(LDAPResultCode.PROTOCOL_ERROR, message);
-    }
-
-
-    return new PasswordPolicyRequestControl(control.getOID(),
-                                            control.isCritical());
-  }
-
-
-
-  /**
-   * Retrieves a string representation of this password policy request control.
-   *
-   * @return  A string representation of this password policy request control.
-   */
-  public String toString()
-  {
-    StringBuilder buffer = new StringBuilder();
-    toString(buffer);
-    return buffer.toString();
+  @Override
+  public void writeValue(ASN1Writer writer) throws IOException {
+    // No value element.
   }
 
 
@@ -125,6 +132,7 @@
    *
    * @param  buffer  The buffer to which the information should be appended.
    */
+  @Override
   public void toString(StringBuilder buffer)
   {
     buffer.append("PasswordPolicyRequestControl()");

--
Gitblit v1.10.0