001/* 002 * Copyright 2008-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2008-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) 2008-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.ldif; 037 038 039 040import java.io.Serializable; 041 042import com.unboundid.ldap.sdk.DN; 043import com.unboundid.ldap.sdk.LDAPException; 044import com.unboundid.util.ByteStringBuffer; 045import com.unboundid.util.NotExtensible; 046import com.unboundid.util.ThreadSafety; 047import com.unboundid.util.ThreadSafetyLevel; 048 049 050 051/** 052 * This interface defines a common API for LDIF records, which are objects that 053 * can be represented using LDIF. This includes both 054 * {@link com.unboundid.ldap.sdk.Entry} and {@link LDIFChangeRecord} objects. 055 * It is possible to obtain the DN of an LDIF record, as well as to obtain the 056 * LDIF representation of that object. They can be read using the 057 * {@link LDIFReader#readLDIFRecord} method and written using the 058 * {@link LDIFWriter#writeLDIFRecord} method. 059 * <BR><BR> 060 * This interface defines a data type that is intended to be implemented only 061 * by classes within the LDAP SDK. Third-party code may reference objects using 062 * this data type, but external classes should not create additional 063 * implementations of this interface. 064 */ 065@NotExtensible() 066@ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE) 067public interface LDIFRecord 068 extends Serializable 069{ 070 /** 071 * Retrieves the string representation of the DN for this LDIF record. 072 * 073 * @return The string representation of the DN for this LDIF record. 074 */ 075 String getDN(); 076 077 078 079 /** 080 * Retrieves the parsed DN for this LDIF record as a {@link DN} object. 081 * 082 * @return The parsed DN for this LDIF record as a {@link DN} object. 083 * 084 * @throws LDAPException If a problem occurs while trying to parse the DN. 085 */ 086 DN getParsedDN() 087 throws LDAPException; 088 089 090 091 /** 092 * Retrieves an LDIF representation of this LDIF record, with each line of 093 * the LDIF representation in a separate element of the returned array. Long 094 * lines will not be wrapped. 095 * 096 * @return An LDIF representation of this LDIF record. 097 */ 098 String[] toLDIF(); 099 100 101 102 /** 103 * Retrieves an LDIF representation of this LDIF record, with each line of 104 * the LDIF representation in a separate element of the returned array. 105 * 106 * @param wrapColumn The column at which to wrap long lines. A value that 107 * is less than or equal to two indicates that no 108 * wrapping should be performed. 109 * 110 * @return An LDIF representation of this LDIF record. 111 */ 112 String[] toLDIF(int wrapColumn); 113 114 115 116 /** 117 * Appends an LDIF-formatted string representation of this LDIF record to the 118 * provided buffer. No wrapping will be performed, and no extra blank lines 119 * will be added. 120 * 121 * @param buffer The buffer to which to append the LDIF representation of 122 * this LDIF record. 123 */ 124 void toLDIF(ByteStringBuffer buffer); 125 126 127 128 /** 129 * Appends an LDIF-formatted string representation of this LDIF record to the 130 * provided buffer. No extra blank lines will be added. 131 * 132 * @param buffer The buffer to which to append the LDIF representation 133 * of this LDIF record. 134 * @param wrapColumn The column at which to wrap long lines. A value that 135 * is less than or equal to two indicates that no 136 * wrapping should be performed. 137 */ 138 void toLDIF(ByteStringBuffer buffer, int wrapColumn); 139 140 141 142 /** 143 * Retrieves an LDIF-formatted string representation of this LDIF record. No 144 * wrapping will be performed, and no extra blank lines will be added. 145 * 146 * @return An LDIF-formatted string representation of this entry. 147 */ 148 String toLDIFString(); 149 150 151 152 /** 153 * Retrieves an LDIF-formatted string representation of this LDIF record. No 154 * extra blank lines will be added. 155 * 156 * @param wrapColumn The column at which to wrap long lines. A value that 157 * is less than or equal to two indicates that no 158 * wrapping should be performed. 159 * 160 * @return An LDIF-formatted string representation of this entry. 161 */ 162 String toLDIFString(int wrapColumn); 163 164 165 166 /** 167 * Appends an LDIF-formatted string representation of this LDIF record to the 168 * provided buffer. No wrapping will be performed, and no extra blank lines 169 * will be added. 170 * 171 * @param buffer The buffer to which to append the LDIF representation of 172 * this LDIF record. 173 */ 174 void toLDIFString(StringBuilder buffer); 175 176 177 178 /** 179 * Appends an LDIF-formatted string representation of this LDIF record to the 180 * provided buffer. No extra blank lines will be added. 181 * 182 * @param buffer The buffer to which to append the LDIF representation 183 * of this LDIF record. 184 * @param wrapColumn The column at which to wrap long lines. A value that 185 * is less than or equal to two indicates that no 186 * wrapping should be performed. 187 */ 188 void toLDIFString(StringBuilder buffer, int wrapColumn); 189 190 191 192 /** 193 * Retrieves a string representation of this LDIF record. Note that it will 194 * be a single-line string representation and will therefore not be an LDIF 195 * representation. 196 * 197 * @return A string representation of this LDIF record. 198 */ 199 @Override() 200 String toString(); 201 202 203 204 /** 205 * Appends a string representation of this LDIF record to the provided buffer. 206 * Note that it will be a single-line string representation and will 207 * therefore not be an LDIF representation. 208 * 209 * @param buffer The buffer to which the string representation of this LDIF 210 * record should be appended. 211 */ 212 void toString(StringBuilder buffer); 213}