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 2014-2016 ForgeRock AS. 016 */ 017package org.opends.server.protocols.ldap; 018 019 020import java.io.IOException; 021 022import org.forgerock.opendj.io.*; 023import org.forgerock.opendj.ldap.ByteString; 024 025import org.forgerock.i18n.slf4j.LocalizedLogger; 026import static org.opends.server.protocols.ldap.LDAPConstants.*; 027import static org.opends.server.util.ServerConstants.*; 028 029 030/** 031 * This class defines the structures and methods for an LDAP extended request 032 * protocol op, which is used to request some special type of processing defined 033 * in an extension to the LDAP protocol. 034 */ 035public class ExtendedRequestProtocolOp 036 extends ProtocolOp 037{ 038 private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); 039 040 /** The value for this extended request. */ 041 private ByteString value; 042 043 /** The OID for this extended request. */ 044 private String oid; 045 046 047 048 /** 049 * Creates a new extended request protocol op with the specified OID and no 050 * value. 051 * 052 * @param oid The OID for this extended request. 053 */ 054 public ExtendedRequestProtocolOp(String oid) 055 { 056 this.oid = oid; 057 this.value = null; 058 } 059 060 061 062 /** 063 * Creates a new extended request protocol op with the specified OID and 064 * value. 065 * 066 * @param oid The OID for this extended request. 067 * @param value The value for this extended request. 068 */ 069 public ExtendedRequestProtocolOp(String oid, ByteString value) 070 { 071 this.oid = oid; 072 this.value = value; 073 } 074 075 076 077 /** 078 * Retrieves the OID for this extended request. 079 * 080 * @return The OID for this extended request. 081 */ 082 public String getOID() 083 { 084 return oid; 085 } 086 087 088 /** 089 * Retrieves the value for this extended request. 090 * 091 * @return The value for this extended request, or <CODE>null</CODE> if there 092 * is no value. 093 */ 094 public ByteString getValue() 095 { 096 return value; 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 @Override 107 public byte getType() 108 { 109 return OP_TYPE_EXTENDED_REQUEST; 110 } 111 112 113 114 /** 115 * Retrieves the name for this protocol op type. 116 * 117 * @return The name for this protocol op type. 118 */ 119 @Override 120 public String getProtocolOpName() 121 { 122 return "Extended Request"; 123 } 124 125 /** 126 * Writes this protocol op to an ASN.1 output stream. 127 * 128 * @param stream The ASN.1 output stream to write to. 129 * @throws IOException If a problem occurs while writing to the stream. 130 */ 131 @Override 132 public void write(ASN1Writer stream) throws IOException 133 { 134 stream.writeStartSequence(OP_TYPE_EXTENDED_REQUEST); 135 stream.writeOctetString(TYPE_EXTENDED_REQUEST_OID, oid); 136 137 if(value != null) 138 { 139 stream.writeOctetString(TYPE_EXTENDED_REQUEST_VALUE, value); 140 } 141 142 stream.writeEndSequence(); 143 } 144 145 146 147 /** 148 * Appends a string representation of this LDAP protocol op to the provided 149 * buffer. 150 * 151 * @param buffer The buffer to which the string should be appended. 152 */ 153 @Override 154 public void toString(StringBuilder buffer) 155 { 156 buffer.append("ExtendedRequest(oid="); 157 buffer.append(oid); 158 159 if (value != null) 160 { 161 buffer.append(", value="); 162 buffer.append(value); 163 } 164 165 buffer.append(")"); 166 } 167 168 169 170 /** 171 * Appends a multi-line string representation of this LDAP protocol op to the 172 * provided buffer. 173 * 174 * @param buffer The buffer to which the information should be appended. 175 * @param indent The number of spaces from the margin that the lines should 176 * be indented. 177 */ 178 @Override 179 public void toString(StringBuilder buffer, int indent) 180 { 181 StringBuilder indentBuf = new StringBuilder(indent); 182 for (int i=0 ; i < indent; i++) 183 { 184 indentBuf.append(' '); 185 } 186 187 buffer.append(indentBuf); 188 buffer.append("Extended Request"); 189 buffer.append(EOL); 190 191 buffer.append(indentBuf); 192 buffer.append(" OID: "); 193 buffer.append(oid); 194 buffer.append(EOL); 195 196 if (value != null) 197 { 198 buffer.append(indentBuf); 199 buffer.append(" Value:"); 200 buffer.append(EOL); 201 buffer.append(value.toHexPlusAsciiString(indent+4)); 202 } 203 } 204} 205