001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2006-2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.dsml.protocol; 028 029 import java.io.IOException; 030 import org.opends.messages.Message; 031 032 import org.opends.server.protocols.ldap.AbandonRequestProtocolOp; 033 import org.opends.server.protocols.ldap.LDAPMessage; 034 import org.opends.server.protocols.ldap.LDAPResultCode; 035 import org.opends.server.protocols.ldap.ProtocolOp; 036 import org.opends.server.tools.LDAPConnection; 037 import org.opends.server.types.LDAPException; 038 039 040 041 /** 042 * This class provides the functionality for the performing an 043 * LDAP ABANDON operation based on the specified DSML request. 044 */ 045 public class DSMLAbandonOperation 046 { 047 private LDAPConnection connection; 048 049 /** 050 * Create an instance with the specified LDAP connection. 051 * 052 * @param connection The LDAP connection to send the request on. 053 */ 054 public DSMLAbandonOperation(LDAPConnection connection) 055 { 056 this.connection = connection; 057 } 058 059 /** 060 * Perform the LDAP ABANDON operation and send the result back to the 061 * client. 062 * 063 * @param objFactory The object factory for this operation. 064 * @param abandonRequest The abandon request for this operation. 065 * 066 * @return The result of the abandon operation. 067 * 068 * @throws IOException If an I/O problem occurs. 069 * 070 * @throws LDAPException If an error occurs while interacting with an LDAP 071 * element. 072 */ 073 public LDAPResult doOperation(ObjectFactory objFactory, 074 AbandonRequest abandonRequest) 075 throws LDAPException, IOException 076 { 077 LDAPResult abandonResponse = objFactory.createLDAPResult(); 078 079 String abandonIdStr = abandonRequest.getAbandonID(); 080 int abandonId = 0; 081 try 082 { 083 abandonId = Integer.parseInt(abandonIdStr); 084 } catch (NumberFormatException nfe) 085 { 086 throw new LDAPException(LDAPResultCode.UNWILLING_TO_PERFORM, 087 Message.raw(nfe.getMessage())); 088 } 089 090 // Create and send an LDAP request to the server. 091 ProtocolOp op = new AbandonRequestProtocolOp(abandonId); 092 LDAPMessage msg = new LDAPMessage(DSMLServlet.nextMessageID(), op); 093 connection.getLDAPWriter().writeMessage(msg); 094 095 return abandonResponse; 096 } 097 098 } 099