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.ldap.sdk.Control; 043import com.unboundid.ldap.sdk.LDAPResult; 044import com.unboundid.util.Extensible; 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 a response that may be 053 * received from a directory server. 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 LDAPResult} class 059 * should be used instead. 060 */ 061@Extensible() 062@NotMutable() 063@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 064public class LDAPResponse 065 implements Serializable 066{ 067 /** 068 * The serial version UID for this serializable class. 069 */ 070 private static final long serialVersionUID = -8401666939604882177L; 071 072 073 074 // The LDAP result for this LDAP response. 075 private final LDAPResult ldapResult; 076 077 078 079 /** 080 * Creates a new LDAP response from the provided {@link LDAPResult}. 081 * 082 * @param ldapResult The {@code LDAPResult} object to use to create this 083 * LDAP response. 084 */ 085 public LDAPResponse(final LDAPResult ldapResult) 086 { 087 this.ldapResult = ldapResult; 088 } 089 090 091 092 /** 093 * Retrieves the LDAP message ID for this LDAP response. 094 * 095 * @return The LDAP message ID for this LDAP response. 096 */ 097 public int getMessageID() 098 { 099 return ldapResult.getMessageID(); 100 } 101 102 103 104 /** 105 * Retrieves the result code for this LDAP response. 106 * 107 * @return The result code for this LDAP response. 108 */ 109 public int getResultCode() 110 { 111 return ldapResult.getResultCode().intValue(); 112 } 113 114 115 116 /** 117 * Retrieves the error message for this LDAP response, if available. 118 * 119 * @return The error message for this LDAP response, or {@code null} if there 120 * is none. 121 */ 122 public String getErrorMessage() 123 { 124 return ldapResult.getDiagnosticMessage(); 125 } 126 127 128 129 /** 130 * Retrieves the matched DN for this LDAP response, if available. 131 * 132 * @return The matched DN for this LDAP response, or {@code null} if there 133 * is none. 134 */ 135 public String getMatchedDN() 136 { 137 return ldapResult.getMatchedDN(); 138 } 139 140 141 142 /** 143 * Retrieves the set of referrals for this LDAP response, if any. 144 * 145 * @return The set of referrals for this LDAP response, or {@code null} if 146 * there are none. 147 */ 148 public String[] getReferrals() 149 { 150 final String[] referrals = ldapResult.getReferralURLs(); 151 if (referrals.length == 0) 152 { 153 return null; 154 } 155 else 156 { 157 return referrals; 158 } 159 } 160 161 162 163 /** 164 * Retrieves the list of controls for this LDAP response, if any. 165 * 166 * @return The list of controls for this LDAP response, or {@code null} if 167 * there are none. 168 */ 169 public LDAPControl[] getControls() 170 { 171 final Control[] controls = ldapResult.getResponseControls(); 172 if (controls.length == 0) 173 { 174 return null; 175 } 176 177 return LDAPControl.toLDAPControls(controls); 178 } 179 180 181 182 /** 183 * Retrieves an {@link LDAPResult} object that is the equivalent of this LDAP 184 * response. 185 * 186 * @return An {@code LDAPResult} object that is the equivalent of this LDAP 187 * response. 188 */ 189 public final LDAPResult toLDAPResult() 190 { 191 return ldapResult; 192 } 193 194 195 196 /** 197 * Retrieves a string representation of this LDAP response. 198 * 199 * @return A string representation of this LDAP response. 200 */ 201 @Override() 202 public String toString() 203 { 204 return ldapResult.toString(); 205 } 206}