001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2009 Sun Microsystems, Inc.
015 * Portions Copyright 2014-2016 ForgeRock AS.
016 */
017package org.opends.server.controls;
018
019
020
021import static org.opends.messages.ProtocolMessages.*;
022import static org.opends.server.util.ServerConstants.*;
023
024import java.io.IOException;
025
026import org.forgerock.i18n.LocalizableMessage;
027import org.forgerock.opendj.io.ASN1Writer;
028import org.forgerock.opendj.ldap.ByteString;
029import org.opends.server.types.Control;
030import org.opends.server.types.DirectoryException;
031import org.forgerock.opendj.ldap.ResultCode;
032
033
034
035/**
036 * This class implements the subtree delete control defined in
037 * draft-armijo-ldap-treedelete. It makes it possible for clients to
038 * delete subtrees of entries.
039 */
040public class SubtreeDeleteControl extends Control
041{
042  /** ControlDecoder implementation to decode this control from a ByteString. */
043  private static final class Decoder implements
044      ControlDecoder<SubtreeDeleteControl>
045  {
046    @Override
047    public SubtreeDeleteControl decode(boolean isCritical,
048        ByteString value) throws DirectoryException
049    {
050      if (value != null)
051      {
052        LocalizableMessage message =
053            ERR_SUBTREE_DELETE_INVALID_CONTROL_VALUE.get();
054        throw new DirectoryException(ResultCode.PROTOCOL_ERROR, message);
055      }
056
057      return new SubtreeDeleteControl(isCritical);
058    }
059
060
061
062    @Override
063    public String getOID()
064    {
065      return OID_SUBTREE_DELETE_CONTROL;
066    }
067
068  }
069
070
071
072  /** The Control Decoder that can be used to decode this control. */
073  public static final ControlDecoder<SubtreeDeleteControl> DECODER =
074      new Decoder();
075
076
077
078  /**
079   * Creates a new subtree delete control.
080   *
081   * @param isCritical
082   *          Indicates whether the control should be considered
083   *          critical for the operation processing.
084   */
085  public SubtreeDeleteControl(boolean isCritical)
086  {
087    super(OID_SUBTREE_DELETE_CONTROL, isCritical);
088  }
089
090
091
092  @Override
093  protected void writeValue(ASN1Writer writer) throws IOException
094  {
095    // Nothing to do.
096  }
097
098
099
100  @Override
101  public void toString(StringBuilder buffer)
102  {
103    buffer.append("SubtreeDeleteControl()");
104  }
105
106}