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.ASN1Null;
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 unbind request
048 * protocol op, which is used to indicate that the client wishes to disconnect
049 * from the Directory Server.
050 */
051 public class UnbindRequestProtocolOp
052 extends ProtocolOp
053 {
054 /**
055 * The tracer object for the debug logger.
056 */
057 private static final DebugTracer TRACER = getTracer();
058
059 /**
060 * Creates a new LDAP unbind request protocol op.
061 */
062 public UnbindRequestProtocolOp()
063 {
064 }
065
066
067
068 /**
069 * Retrieves the BER type for this protocol op.
070 *
071 * @return The BER type for this protocol op.
072 */
073 public byte getType()
074 {
075 return OP_TYPE_UNBIND_REQUEST;
076 }
077
078
079
080 /**
081 * Retrieves the name for this protocol op type.
082 *
083 * @return The name for this protocol op type.
084 */
085 public String getProtocolOpName()
086 {
087 return "Unbind Request";
088 }
089
090
091
092 /**
093 * Encodes this protocol op to an ASN.1 element suitable for including in an
094 * LDAP message.
095 *
096 * @return The ASN.1 element containing the encoded protocol op.
097 */
098 public ASN1Element encode()
099 {
100 return new ASN1Null(OP_TYPE_UNBIND_REQUEST);
101 }
102
103
104
105 /**
106 * Decodes the provided ASN.1 element as an LDAP unbind request protocol op.
107 *
108 * @param element The ASN.1 element to decode.
109 *
110 * @return The decoded LDAP unbind request protocol op.
111 *
112 * @throws LDAPException If the provided ASN.1 element cannot be decoded as
113 * an unbind request protocol op.
114 */
115 public static UnbindRequestProtocolOp decodeUnbindRequest(ASN1Element element)
116 throws LDAPException
117 {
118 try
119 {
120 element.decodeAsNull();
121 return new UnbindRequestProtocolOp();
122 }
123 catch (Exception e)
124 {
125 if (debugEnabled())
126 {
127 TRACER.debugCaught(DebugLogLevel.ERROR, e);
128 }
129
130 Message message = ERR_LDAP_UNBIND_DECODE.get(String.valueOf(e));
131 throw new LDAPException(PROTOCOL_ERROR, message, e);
132 }
133 }
134
135
136
137 /**
138 * Appends a string representation of this LDAP protocol op to the provided
139 * buffer.
140 *
141 * @param buffer The buffer to which the string should be appended.
142 */
143 public void toString(StringBuilder buffer)
144 {
145 buffer.append("UnbindRequest()");
146 }
147
148
149
150 /**
151 * Appends a multi-line string representation of this LDAP protocol op to the
152 * provided buffer.
153 *
154 * @param buffer The buffer to which the information should be appended.
155 * @param indent The number of spaces from the margin that the lines should
156 * be indented.
157 */
158 public void toString(StringBuilder buffer, int indent)
159 {
160 for (int i=0; i < indent; i++)
161 {
162 buffer.append(' ');
163 }
164
165 buffer.append("Unbind Request");
166 buffer.append(EOL);
167 }
168 }
169