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.server.protocols.ldap;
028    import org.opends.messages.Message;
029    
030    
031    
032    import org.opends.server.protocols.asn1.ASN1Element;
033    import org.opends.server.protocols.asn1.ASN1Integer;
034    import org.opends.server.types.DebugLogLevel;
035    import org.opends.server.types.LDAPException;
036    
037    import static org.opends.server.loggers.debug.DebugLogger.*;
038    import org.opends.server.loggers.debug.DebugTracer;
039    import static org.opends.messages.ProtocolMessages.*;
040    import static org.opends.server.protocols.ldap.LDAPConstants.*;
041    import static org.opends.server.protocols.ldap.LDAPResultCode.*;
042    import static org.opends.server.util.ServerConstants.*;
043    
044    
045    
046    /**
047     * This class defines the structures and methods for an LDAP abandon request
048     * protocol op, which is used to indicate that the server should stop processing
049     * a previously requested operation.
050     */
051    public class AbandonRequestProtocolOp
052           extends ProtocolOp
053    {
054      /**
055       * The tracer object for the debug logger.
056       */
057      private static final DebugTracer TRACER = getTracer();
058    
059      // The message ID of the operation to abandon.
060      private int idToAbandon;
061    
062    
063    
064      /**
065       * Creates a new abandon request protocol op to abandon the specified
066       * operation.
067       *
068       * @param  idToAbandon  The message ID of the operation to abandon.
069       */
070      public AbandonRequestProtocolOp(int idToAbandon)
071      {
072        this.idToAbandon = idToAbandon;
073      }
074    
075    
076    
077      /**
078       * Retrieves the message ID of the operation to abandon.
079       *
080       * @return  The message ID of the operation to abandon.
081       */
082      public int getIDToAbandon()
083      {
084        return idToAbandon;
085      }
086    
087    
088    
089      /**
090       * Specifies the message ID of the operation to abandon.
091       *
092       * @param  idToAbandon  The message ID of the operation to abandon.
093       */
094      public void setIDToAbandon(int idToAbandon)
095      {
096        this.idToAbandon = idToAbandon;
097      }
098    
099    
100    
101      /**
102       * Retrieves the BER type for this protocol op.
103       *
104       * @return  The BER type for this protocol op.
105       */
106      public byte getType()
107      {
108        return OP_TYPE_ABANDON_REQUEST;
109      }
110    
111    
112    
113      /**
114       * Retrieves the name for this protocol op type.
115       *
116       * @return  The name for this protocol op type.
117       */
118      public String getProtocolOpName()
119      {
120        return "Abandon Request";
121      }
122    
123    
124    
125      /**
126       * Encodes this protocol op to an ASN.1 element suitable for including in an
127       * LDAP message.
128       *
129       * @return  The ASN.1 element containing the encoded protocol op.
130       */
131      public ASN1Element encode()
132      {
133        return new ASN1Integer(OP_TYPE_ABANDON_REQUEST, idToAbandon);
134      }
135    
136    
137    
138      /**
139       * Decodes the provided ASN.1 element as an abandon request protocol op.
140       *
141       * @param  element  The ASN.1 element to decode.
142       *
143       * @return  The decoded abandon request protocol op.
144       *
145       * @throws  LDAPException  If the provided ASN.1 element cannot be decoded as
146       *                         an abandon request protocol op.
147       */
148      public static AbandonRequestProtocolOp decodeAbandonRequest(ASN1Element
149                                                                       element)
150             throws LDAPException
151      {
152        int idToAbandon;
153        try
154        {
155          idToAbandon = element.decodeAsInteger().intValue();
156        }
157        catch (Exception e)
158        {
159          if (debugEnabled())
160          {
161            TRACER.debugCaught(DebugLogLevel.ERROR, e);
162          }
163    
164          Message message =
165              ERR_LDAP_ABANDON_REQUEST_DECODE_ID.get(String.valueOf(e));
166          throw new LDAPException(PROTOCOL_ERROR, message, e);
167        }
168    
169        return new AbandonRequestProtocolOp(idToAbandon);
170      }
171    
172    
173    
174      /**
175       * Appends a string representation of this LDAP protocol op to the provided
176       * buffer.
177       *
178       * @param  buffer  The buffer to which the string should be appended.
179       */
180      public void toString(StringBuilder buffer)
181      {
182        buffer.append("AbandonRequest(idToAbandon=");
183        buffer.append(idToAbandon);
184        buffer.append(")");
185      }
186    
187    
188    
189      /**
190       * Appends a multi-line string representation of this LDAP protocol op to the
191       * provided buffer.
192       *
193       * @param  buffer  The buffer to which the information should be appended.
194       * @param  indent  The number of spaces from the margin that the lines should
195       *                 be indented.
196       */
197      public void toString(StringBuilder buffer, int indent)
198      {
199        StringBuilder indentBuf = new StringBuilder(indent);
200        for (int i=0 ; i < indent; i++)
201        {
202          indentBuf.append(' ');
203        }
204    
205        buffer.append(indentBuf);
206        buffer.append("Abandon Request");
207        buffer.append(EOL);
208    
209        buffer.append(indentBuf);
210        buffer.append("  ID to Abandon:  ");
211        buffer.append(idToAbandon);
212        buffer.append(EOL);
213      }
214    }
215