Package com.unboundid.ldif
Class LDIFChangeRecord
- java.lang.Object
-
- com.unboundid.ldif.LDIFChangeRecord
-
- All Implemented Interfaces:
LDIFRecord,java.io.Serializable
- Direct Known Subclasses:
LDIFAddChangeRecord,LDIFDeleteChangeRecord,LDIFModifyChangeRecord,LDIFModifyDNChangeRecord
@NotExtensible @ThreadSafety(level=INTERFACE_THREADSAFE) public abstract class LDIFChangeRecord extends java.lang.Object implements LDIFRecord
This class provides a base class for LDIF change records, which can be used to represent add, delete, modify, and modify DN operations in LDIF form.
Example
The following example iterates through all of the change records contained in an LDIF file and attempts to apply those changes to a directory server:LDIFReader ldifReader = new LDIFReader(pathToLDIFFile); int changesRead = 0; int changesProcessed = 0; int errorsEncountered = 0; while (true) { LDIFChangeRecord changeRecord; try { changeRecord = ldifReader.readChangeRecord(); if (changeRecord == null) { // All changes have been processed. break; } changesRead++; } catch (LDIFException le) { errorsEncountered++; if (le.mayContinueReading()) { // A recoverable error occurred while attempting to read a change // record, at or near line number le.getLineNumber() // The change record will be skipped, but we'll try to keep reading // from the LDIF file. continue; } else { // An unrecoverable error occurred while attempting to read a change // record, at or near line number le.getLineNumber() // No further LDIF processing will be performed. break; } } catch (IOException ioe) { // An I/O error occurred while attempting to read from the LDIF file. // No further LDIF processing will be performed. errorsEncountered++; break; } // Try to process the change in a directory server. LDAPResult operationResult; try { operationResult = changeRecord.processChange(connection); // If we got here, then the change should have been processed // successfully. changesProcessed++; } catch (LDAPException le) { // If we got here, then the change attempt failed. operationResult = le.toLDAPResult(); errorsEncountered++; } } ldifReader.close();- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedLDIFChangeRecord(java.lang.String dn, java.util.List<Control> controls)Creates a new LDIF change record with the provided DN.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract LDIFChangeRecordduplicate(Control... controls)Creates a duplicate of this LDIF change record with the provided set of controls.abstract booleanequals(java.lang.Object o)Indicates whether the provided object is equal to this LDIF change record.abstract ChangeTypegetChangeType()Retrieves the type of operation represented by this LDIF change record.java.util.List<Control>getControls()Retrieves the set of controls for this LDIF change record.java.lang.StringgetDN()Retrieves the DN for this LDIF change record.DNgetParsedDN()Retrieves the parsed DN for this LDIF change record.abstract inthashCode()Retrieves a hash code for this change record.LDAPResultprocessChange(LDAPInterface connection)Apply the change represented by this LDIF change record to a directory server using the provided connection.abstract LDAPResultprocessChange(LDAPInterface connection, boolean includeControls)Apply the change represented by this LDIF change record to a directory server using the provided connection, optionally including any change record controls in the request.java.lang.String[]toLDIF()Retrieves a string array whose lines contain an LDIF representation of this change record.abstract java.lang.String[]toLDIF(int wrapColumn)Retrieves a string array whose lines contain an LDIF representation of this change record.voidtoLDIF(ByteStringBuffer buffer)Appends an LDIF string representation of this change record to the provided buffer.abstract voidtoLDIF(ByteStringBuffer buffer, int wrapColumn)Appends an LDIF string representation of this change record to the provided buffer.java.lang.StringtoLDIFString()Retrieves an LDIF string representation of this change record.java.lang.StringtoLDIFString(int wrapColumn)Retrieves an LDIF string representation of this change record.voidtoLDIFString(java.lang.StringBuilder buffer)Appends an LDIF string representation of this change record to the provided buffer.abstract voidtoLDIFString(java.lang.StringBuilder buffer, int wrapColumn)Appends an LDIF string representation of this change record to the provided buffer.java.lang.StringtoString()Retrieves a single-line string representation of this change record.abstract voidtoString(java.lang.StringBuilder buffer)Appends a single-line string representation of this change record to the provided buffer.
-
-
-
Constructor Detail
-
LDIFChangeRecord
protected LDIFChangeRecord(@NotNull java.lang.String dn, @Nullable java.util.List<Control> controls)
Creates a new LDIF change record with the provided DN.- Parameters:
dn- The DN of the LDIF change record to create. It must not benull.controls- The set of controls for the change record to create. It may benullor empty if no controls are needed.
-
-
Method Detail
-
getDN
@NotNull public final java.lang.String getDN()
Retrieves the DN for this LDIF change record.- Specified by:
getDNin interfaceLDIFRecord- Returns:
- The DN for this LDIF change record.
-
getParsedDN
@NotNull public final DN getParsedDN() throws LDAPException
Retrieves the parsed DN for this LDIF change record.- Specified by:
getParsedDNin interfaceLDIFRecord- Returns:
- The DN for this LDIF change record.
- Throws:
LDAPException- If a problem occurs while trying to parse the DN.
-
getChangeType
@NotNull public abstract ChangeType getChangeType()
Retrieves the type of operation represented by this LDIF change record.- Returns:
- The type of operation represented by this LDIF change record.
-
getControls
@NotNull public java.util.List<Control> getControls()
Retrieves the set of controls for this LDIF change record.- Returns:
- The set of controls for this LDIF change record, or an empty array if there are no controls.
-
duplicate
@NotNull public abstract LDIFChangeRecord duplicate(@Nullable Control... controls)
Creates a duplicate of this LDIF change record with the provided set of controls.- Parameters:
controls- The set of controls to include in the duplicate change record. It may benullor empty if no controls should be included.- Returns:
- A duplicate of this LDIF change record with the provided set of controls.
-
processChange
@NotNull public final LDAPResult processChange(@NotNull LDAPInterface connection) throws LDAPException
Apply the change represented by this LDIF change record to a directory server using the provided connection. Any controls included in the change record will be included in the request.- Parameters:
connection- The connection to use to apply the change.- Returns:
- An object providing information about the result of the operation.
- Throws:
LDAPException- If an error occurs while processing this change in the associated directory server.
-
processChange
@NotNull public abstract LDAPResult processChange(@NotNull LDAPInterface connection, boolean includeControls) throws LDAPException
Apply the change represented by this LDIF change record to a directory server using the provided connection, optionally including any change record controls in the request.- Parameters:
connection- The connection to use to apply the change.includeControls- Indicates whether to include any controls in the request.- Returns:
- An object providing information about the result of the operation.
- Throws:
LDAPException- If an error occurs while processing this change in the associated directory server.
-
toLDIF
@NotNull public final java.lang.String[] toLDIF()
Retrieves a string array whose lines contain an LDIF representation of this change record.- Specified by:
toLDIFin interfaceLDIFRecord- Returns:
- A string array whose lines contain an LDIF representation of this change record.
-
toLDIF
@NotNull public abstract java.lang.String[] toLDIF(int wrapColumn)
Retrieves a string array whose lines contain an LDIF representation of this change record.- Specified by:
toLDIFin interfaceLDIFRecord- Parameters:
wrapColumn- The column at which to wrap long lines. A value that is less than or equal to two indicates that no wrapping should be performed.- Returns:
- A string array whose lines contain an LDIF representation of this change record.
-
toLDIF
public final void toLDIF(@NotNull ByteStringBuffer buffer)
Appends an LDIF string representation of this change record to the provided buffer.- Specified by:
toLDIFin interfaceLDIFRecord- Parameters:
buffer- The buffer to which to append an LDIF representation of this change record.
-
toLDIF
public abstract void toLDIF(@NotNull ByteStringBuffer buffer, int wrapColumn)
Appends an LDIF string representation of this change record to the provided buffer.- Specified by:
toLDIFin interfaceLDIFRecord- Parameters:
buffer- The buffer to which to append an LDIF representation of this change record.wrapColumn- The column at which to wrap long lines. A value that is less than or equal to two indicates that no wrapping should be performed.
-
toLDIFString
@NotNull public final java.lang.String toLDIFString()
Retrieves an LDIF string representation of this change record.- Specified by:
toLDIFStringin interfaceLDIFRecord- Returns:
- An LDIF string representation of this change record.
-
toLDIFString
@NotNull public final java.lang.String toLDIFString(int wrapColumn)
Retrieves an LDIF string representation of this change record.- Specified by:
toLDIFStringin interfaceLDIFRecord- Parameters:
wrapColumn- The column at which to wrap long lines. A value that is less than or equal to two indicates that no wrapping should be performed.- Returns:
- An LDIF string representation of this change record.
-
toLDIFString
public final void toLDIFString(@NotNull java.lang.StringBuilder buffer)
Appends an LDIF string representation of this change record to the provided buffer.- Specified by:
toLDIFStringin interfaceLDIFRecord- Parameters:
buffer- The buffer to which to append an LDIF representation of this change record.
-
toLDIFString
public abstract void toLDIFString(@NotNull java.lang.StringBuilder buffer, int wrapColumn)
Appends an LDIF string representation of this change record to the provided buffer.- Specified by:
toLDIFStringin interfaceLDIFRecord- Parameters:
buffer- The buffer to which to append an LDIF representation of this change record.wrapColumn- The column at which to wrap long lines. A value that is less than or equal to two indicates that no wrapping should be performed.
-
hashCode
public abstract int hashCode()
Retrieves a hash code for this change record.- Overrides:
hashCodein classjava.lang.Object- Returns:
- A hash code for this change record.
-
equals
public abstract boolean equals(@Nullable java.lang.Object o)
Indicates whether the provided object is equal to this LDIF change record.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- The object for which to make the determination.- Returns:
trueif the provided object is equal to this LDIF change record, orfalseif not.
-
toString
@NotNull public final java.lang.String toString()
Retrieves a single-line string representation of this change record.- Specified by:
toStringin interfaceLDIFRecord- Overrides:
toStringin classjava.lang.Object- Returns:
- A single-line string representation of this change record.
-
toString
public abstract void toString(@NotNull java.lang.StringBuilder buffer)
Appends a single-line string representation of this change record to the provided buffer.- Specified by:
toStringin interfaceLDIFRecord- Parameters:
buffer- The buffer to which the information should be written.
-
-