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-2015 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 public byte getType() 107 { 108 return OP_TYPE_EXTENDED_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 "Extended Request"; 121 } 122 123 /** 124 * Writes this protocol op to an ASN.1 output stream. 125 * 126 * @param stream The ASN.1 output stream to write to. 127 * @throws IOException If a problem occurs while writing to the stream. 128 */ 129 public void write(ASN1Writer stream) throws IOException 130 { 131 stream.writeStartSequence(OP_TYPE_EXTENDED_REQUEST); 132 stream.writeOctetString(TYPE_EXTENDED_REQUEST_OID, oid); 133 134 if(value != null) 135 { 136 stream.writeOctetString(TYPE_EXTENDED_REQUEST_VALUE, value); 137 } 138 139 stream.writeEndSequence(); 140 } 141 142 143 144 /** 145 * Appends a string representation of this LDAP protocol op to the provided 146 * buffer. 147 * 148 * @param buffer The buffer to which the string should be appended. 149 */ 150 public void toString(StringBuilder buffer) 151 { 152 buffer.append("ExtendedRequest(oid="); 153 buffer.append(oid); 154 155 if (value != null) 156 { 157 buffer.append(", value="); 158 buffer.append(value); 159 } 160 161 buffer.append(")"); 162 } 163 164 165 166 /** 167 * Appends a multi-line string representation of this LDAP protocol op to the 168 * provided buffer. 169 * 170 * @param buffer The buffer to which the information should be appended. 171 * @param indent The number of spaces from the margin that the lines should 172 * be indented. 173 */ 174 public void toString(StringBuilder buffer, int indent) 175 { 176 StringBuilder indentBuf = new StringBuilder(indent); 177 for (int i=0 ; i < indent; i++) 178 { 179 indentBuf.append(' '); 180 } 181 182 buffer.append(indentBuf); 183 buffer.append("Extended Request"); 184 buffer.append(EOL); 185 186 buffer.append(indentBuf); 187 buffer.append(" OID: "); 188 buffer.append(oid); 189 buffer.append(EOL); 190 191 if (value != null) 192 { 193 buffer.append(indentBuf); 194 buffer.append(" Value:"); 195 buffer.append(EOL); 196 buffer.append(value.toHexPlusAsciiString(indent+4)); 197 } 198 } 199} 200