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 2006-2008 Sun Microsystems, Inc.
015 * Portions Copyright 2012-2014 ForgeRock AS.
016 */
017package org.opends.dsml.protocol;
018
019import java.io.IOException;
020import java.util.List;
021
022import org.forgerock.i18n.LocalizableMessage;
023
024import org.opends.server.protocols.ldap.AbandonRequestProtocolOp;
025import org.opends.server.protocols.ldap.LDAPMessage;
026import org.opends.server.protocols.ldap.LDAPResultCode;
027import org.opends.server.protocols.ldap.ProtocolOp;
028import org.opends.server.tools.LDAPConnection;
029import org.opends.server.types.LDAPException;
030
031
032
033/**
034 * This class provides the functionality for the performing an
035 * LDAP ABANDON operation based on the specified DSML request.
036 */
037public class DSMLAbandonOperation
038{
039  private LDAPConnection connection;
040
041  /**
042   * Create an instance with the specified LDAP connection.
043   *
044   * @param connection    The LDAP connection to send the request on.
045   */
046  public DSMLAbandonOperation(LDAPConnection connection)
047  {
048    this.connection = connection;
049  }
050
051  /**
052   * Perform the LDAP ABANDON operation and send the result back to the
053   * client.
054   *
055   * @param  objFactory      The object factory for this operation.
056   * @param  abandonRequest  The abandon request for this operation.
057   * @param  controls        Any required controls (e.g. for proxy authz).
058   *
059   * @return  The result of the abandon operation.
060   *
061   * @throws  IOException  If an I/O problem occurs.
062   *
063   * @throws  LDAPException  If an error occurs while interacting with an LDAP
064   *                         element.
065   */
066  public LDAPResult doOperation(ObjectFactory objFactory,
067        AbandonRequest abandonRequest,
068        List<org.opends.server.types.Control> controls)
069    throws LDAPException, IOException
070  {
071    LDAPResult abandonResponse = objFactory.createLDAPResult();
072
073    String abandonIdStr = abandonRequest.getAbandonID();
074    int abandonId = 0;
075    try
076    {
077      abandonId = Integer.parseInt(abandonIdStr);
078    } catch (NumberFormatException nfe)
079    {
080      throw new LDAPException(LDAPResultCode.UNWILLING_TO_PERFORM,
081                              LocalizableMessage.raw(nfe.getMessage()));
082    }
083
084    // Create and send an LDAP request to the server.
085    ProtocolOp op = new AbandonRequestProtocolOp(abandonId);
086    LDAPMessage msg = new LDAPMessage(DSMLServlet.nextMessageID(), op,
087        controls);
088    connection.getLDAPWriter().writeMessage(msg);
089
090    return abandonResponse;
091  }
092
093}
094