001/* 002 * Copyright 2009-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2009-2020 Ping Identity Corporation 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020/* 021 * Copyright (C) 2009-2020 Ping Identity Corporation 022 * 023 * This program is free software; you can redistribute it and/or modify 024 * it under the terms of the GNU General Public License (GPLv2 only) 025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 026 * as published by the Free Software Foundation. 027 * 028 * This program is distributed in the hope that it will be useful, 029 * but WITHOUT ANY WARRANTY; without even the implied warranty of 030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 031 * GNU General Public License for more details. 032 * 033 * You should have received a copy of the GNU General Public License 034 * along with this program; if not, see <http://www.gnu.org/licenses>. 035 */ 036package com.unboundid.ldap.sdk.migrate.ldapjdk; 037 038 039 040import java.io.Serializable; 041 042import com.unboundid.asn1.ASN1OctetString; 043import com.unboundid.ldap.sdk.ExtendedRequest; 044import com.unboundid.util.NotExtensible; 045import com.unboundid.util.NotMutable; 046import com.unboundid.util.ThreadSafety; 047import com.unboundid.util.ThreadSafetyLevel; 048 049 050 051/** 052 * This class provides a data structure that represents an LDAP extended 053 * request. 054 * <BR><BR> 055 * This class is primarily intended to be used in the process of updating 056 * applications which use the Netscape Directory SDK for Java to switch to or 057 * coexist with the UnboundID LDAP SDK for Java. For applications not written 058 * using the Netscape Directory SDK for Java, the {@link ExtendedRequest} class 059 * should be used instead. 060 */ 061@NotExtensible() 062@NotMutable() 063@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 064public class LDAPExtendedOperation 065 implements Serializable 066{ 067 /** 068 * The serial version UID for this serializable class. 069 */ 070 private static final long serialVersionUID = 9207085503424216431L; 071 072 073 074 // The value for this extended operation, if available. 075 private final byte[] value; 076 077 // The OID for this extended operation. 078 private final String oid; 079 080 081 082 /** 083 * Creates a new LDAP extended operation with the provided OID and value. 084 * 085 * @param id The OID for this extended request. 086 * @param vals The encoded value for this extended request, or {@code null} 087 * if there is none. 088 */ 089 public LDAPExtendedOperation(final String id, final byte[] vals) 090 { 091 oid = id; 092 value = vals; 093 } 094 095 096 097 /** 098 * Creates a new LDAP extended operation from the provided extended request. 099 * 100 * @param extendedRequest The extended request to use to create this LDAP 101 * extended operation. 102 */ 103 public LDAPExtendedOperation(final ExtendedRequest extendedRequest) 104 { 105 oid = extendedRequest.getOID(); 106 107 final ASN1OctetString v = extendedRequest.getValue(); 108 if (v == null) 109 { 110 value = null; 111 } 112 else 113 { 114 value = v.getValue(); 115 } 116 } 117 118 119 120 /** 121 * Retrieves the OID for this LDAP extended operation. 122 * 123 * @return The OID for this LDaP extended operation. 124 */ 125 public String getID() 126 { 127 return oid; 128 } 129 130 131 132 /** 133 * Retrieves the encoded value for this LDAP extended operation, if 134 * available. 135 * 136 * @return The encoded value for this LDAP extended operation, or 137 * {@code null} if there is none. 138 */ 139 public byte[] getValue() 140 { 141 return value; 142 } 143 144 145 146 /** 147 * Converts this LDAP extended operation to an {@link ExtendedRequest}. 148 * 149 * @return The {@code ExtendedRequest} object that is the equivalent of this 150 * LDAP extended response. 151 */ 152 public final ExtendedRequest toExtendedRequest() 153 { 154 if (value == null) 155 { 156 return new ExtendedRequest(oid); 157 } 158 else 159 { 160 return new ExtendedRequest(oid, new ASN1OctetString(value)); 161 } 162 } 163 164 165 166 /** 167 * Retrieves a string representation of this extended operation. 168 * 169 * @return A string representation of this extended operation. 170 */ 171 @Override() 172 public String toString() 173 { 174 final StringBuilder buffer = new StringBuilder(); 175 176 buffer.append("LDAPExtendedOperation(id="); 177 buffer.append(oid); 178 179 if (value != null) 180 { 181 buffer.append(", value=byte["); 182 buffer.append(value.length); 183 buffer.append(']'); 184 } 185 186 buffer.append(')'); 187 188 return buffer.toString(); 189 } 190}