Class Entries
- java.lang.Object
-
- org.forgerock.opendj.ldap.Entries
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEntries.DiffStrategyDefines the available strategy to compute changes.static classEntries.NullEntryAnEntrywhich implements the null object pattern.static classEntries.ReplaceStrategyDefines the available strategy to generate changes.
-
Field Summary
Fields Modifier and Type Field Description static Option<AttributeFilter>ATTRIBUTE_FILTERSelects which attributes will be compared.static Option<Entries.DiffStrategy>DIFF_STRATEGYDefines the strategy to use to compute changes.static Option<Entries.ReplaceStrategy>REPLACE_STRATEGYDefines the strategy to use to generate changes.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Comparator<Entry>compareByName()Returns aComparatorwhich can be used to compare entries by name using the natural order for DN comparisons (parent before children).static booleanconformsToSchema(Entry entry, SchemaValidationPolicy policy, Collection<LocalizableMessage> errorMessages)Returnstrueif the provided entry is valid according to the default schema and schema validation policy.static booleanconformsToSchema(Entry entry, SchemaValidationPolicy policy, Collection<LocalizableMessage> errorMessages, Schema schema)Returnstrueif the provided entry is valid according to the specified schema and schema validation policy.static booleancontainsObjectClass(Entry entry, ObjectClass objectClass)Check if the provided entry contains the provided object class.static booleancontainsObjectClass(Entry entry, ObjectClass objectClass, Schema schema)Check if the provided entry contains the provided object class.static EntrycopyOnWriteEntry(Entry entry, Function<Entry,Entry> copyConstructor)Returns a shallow copy-on-write view ofentry.static ModifyRequestdiffEntries(Entry fromEntry, Entry toEntry)Creates a new modify request containing a list of modifications which can be used to transformfromEntryinto entrytoEntry.static ModifyRequestdiffEntries(Entry fromEntry, Entry toEntry, Options options)Creates a new modify request containing a list of modifications which can be used to transformfromEntryinto entrytoEntry.static Set<ObjectClass>getObjectClasses(Entry entry)Returns an unmodifiable set containing the object classes associated with the provided entry.static Set<ObjectClass>getObjectClasses(Entry entry, Schema schema)Returns an unmodifiable set containing the object classes associated with the provided entry.static ObjectClassgetStructuralObjectClass(Entry entry)Returns the structural object class associated with the provided entry, ornullif none was found.static ObjectClassgetStructuralObjectClass(Entry entry, Schema schema)Returns the structural object class associated with the provided entry, ornullif none was found.static booleanisSubEntry(Entry entry)Returns whether the provided entry is a sub entry.static List<Entry>makeEntries(String... ldifLines)Builds a list of entries from the provided lines of LDIF.static EntrymakeEntry(String... ldifLines)Builds an entry from the provided lines of LDIF.static EntrymodifyEntry(Entry entry, ModifyRequest changes)Applies the provided modification request to an entry.static EntrymodifyEntry(Entry entry, Modification change)Applies the provided modification to an entry.static EntrymodifyEntry(Entry entry, Modification change, Collection<? super ByteString> conflictingValues)Applies the provided modification to an entry.static EntrymodifyEntryPermissive(Entry entry, Collection<Modification> changes)Applies the provided modifications to an entry using "permissive" modify semantics.static EntrymodifyEntryStrict(Entry entry, Collection<Modification> changes)Applies the provided modifications to an entry using "strict" modify semantics.static EntrynullEntry()Returns a read-only empty entry having the empty distinguished name.static EntrynullEntry(Dn dn)Returns a read-only empty entry having the provided distinguished name.static StringtoLdif(Entry entry)Returns the LDIF representation ofentry.static EntryunmodifiableEntry(Entry entry)Returns a read-only view ofentryand its attributes.
-
-
-
Field Detail
-
ATTRIBUTE_FILTER
public static final Option<AttributeFilter> ATTRIBUTE_FILTER
Selects which attributes will be compared. By default all user attributes will be compared.
-
REPLACE_STRATEGY
public static final Option<Entries.ReplaceStrategy> REPLACE_STRATEGY
Defines the strategy to use to generate changes.
-
DIFF_STRATEGY
public static final Option<Entries.DiffStrategy> DIFF_STRATEGY
Defines the strategy to use to compute changes.
-
-
Method Detail
-
compareByName
public static Comparator<Entry> compareByName()
Returns aComparatorwhich can be used to compare entries by name using the natural order for DN comparisons (parent before children).In order to sort entries in reverse order (children first) use the following code:
Collections.reverseOrder(Entries.compareByName());
For more complex sort orders involving one or more attributes refer to theSortKeyclass.- Returns:
- The
Comparator.
-
conformsToSchema
public static boolean conformsToSchema(Entry entry, SchemaValidationPolicy policy, Collection<LocalizableMessage> errorMessages, Schema schema)
Returnstrueif the provided entry is valid according to the specified schema and schema validation policy.If attribute value validation is enabled then following checks will be performed:
- checking that there is at least one value
- checking that single-valued attributes contain only a single value
- Parameters:
entry- The entry to be validated.policy- The schema validation policy.errorMessages- A collection into which any schema validation warnings or error messages can be placed, ornullif they should not be saved.schema- The schema against which the entry will be validated.- Returns:
trueif the provided entry is valid according to the specified schema and schema validation policy.- See Also:
Schema.validateEntry(Entry, SchemaValidationPolicy, Collection)
-
conformsToSchema
public static boolean conformsToSchema(Entry entry, SchemaValidationPolicy policy, Collection<LocalizableMessage> errorMessages)
Returnstrueif the provided entry is valid according to the default schema and schema validation policy.If attribute value validation is enabled then following checks will be performed:
- checking that there is at least one value
- checking that single-valued attributes contain only a single value
- Parameters:
entry- The entry to be validated.policy- The schema validation policy.errorMessages- A collection into which any schema validation warnings or error messages can be placed, ornullif they should not be saved.- Returns:
trueif the provided entry is valid according to the default schema and schema validation policy.- See Also:
Schema.validateEntry(Entry, SchemaValidationPolicy, Collection)
-
containsObjectClass
public static boolean containsObjectClass(Entry entry, ObjectClass objectClass)
Check if the provided entry contains the provided object class.This method uses the default schema for decoding the object class attribute values.
If the default schema is strict then the provided object class must be recognized by the schema, otherwise the method will return
false.- Parameters:
entry- The entry which is checked against the object class.objectClass- The object class to check.- Returns:
trueif the entry contains the object class.
-
containsObjectClass
public static boolean containsObjectClass(Entry entry, ObjectClass objectClass, Schema schema)
Check if the provided entry contains the provided object class.If the provided schema is strict then the provided object class must be recognized by the schema, otherwise the method will return
false.- Parameters:
entry- The entry which is checked against the object class.objectClass- The object class to check.schema- The schema which should be used for decoding the object class attribute values.- Returns:
trueif the entry contains the object class.
-
diffEntries
public static ModifyRequest diffEntries(Entry fromEntry, Entry toEntry)
Creates a new modify request containing a list of modifications which can be used to transformfromEntryinto entrytoEntry.The changes will be generated using a default set of
options. More specifically, only user attributes will be compared, attributes will be compared using their matching rules, and all generated changes will be reversible: it will contain only modifications of typeDELETEthenADD.Finally, the modify request will use the distinguished name taken from
fromEntry. This method will not check to see if bothfromEntryandtoEntryhave the same distinguished name.This method is equivalent to:
ModifyRequest request = Requests.newModifyRequest(fromEntry, toEntry);
Or:ModifyRequest request = diffEntries(fromEntry, toEntry, Options.defaultOptions());
- Parameters:
fromEntry- The source entry.toEntry- The destination entry.- Returns:
- A modify request containing a list of modifications which can be
used to transform
fromEntryinto entrytoEntry. The returned request will always be non-nullbut may not contain any modifications. - Throws:
NullPointerException- IffromEntryortoEntrywerenull.- See Also:
Requests.newModifyRequest(Entry, Entry)
-
diffEntries
public static ModifyRequest diffEntries(Entry fromEntry, Entry toEntry, Options options)
Creates a new modify request containing a list of modifications which can be used to transformfromEntryinto entrytoEntry.The changes will be generated using the provided set of
Options.Finally, the modify request will use the distinguished name taken from
fromEntry. This method will not check to see if bothfromEntryandtoEntryhave the same distinguished name.- Parameters:
fromEntry- The source entry.toEntry- The destination entry.options- The set of options which will control which attributes are compared, how they are compared, and the type of modifications generated.- Returns:
- A modify request containing a list of modifications which can be
used to transform
fromEntryinto entrytoEntry. The returned request will always be non-nullbut may not contain any modifications. - Throws:
NullPointerException- IffromEntry,toEntry, oroptionswerenull.
-
getObjectClasses
public static Set<ObjectClass> getObjectClasses(Entry entry)
Returns an unmodifiable set containing the object classes associated with the provided entry. If the default schema is strict then unrecognized object classes will not be included in the returned set, otherwise place-holder object classes will be returned.This method uses the default schema for decoding the object class attribute values.
- Parameters:
entry- The entry whose object classes are required.- Returns:
- An unmodifiable set containing the object classes associated with the provided entry.
-
getObjectClasses
public static Set<ObjectClass> getObjectClasses(Entry entry, Schema schema)
Returns an unmodifiable set containing the object classes associated with the provided entry. If the provided schema is strict then unrecognized object classes will not be included in the returned set, otherwise place-holder object classes will be returned.- Parameters:
entry- The entry whose object classes are required.schema- The schema which should be used for decoding the object class attribute values.- Returns:
- An unmodifiable set containing the object classes associated with the provided entry.
-
getStructuralObjectClass
public static ObjectClass getStructuralObjectClass(Entry entry)
Returns the structural object class associated with the provided entry, ornullif none was found. If the entry contains multiple structural object classes then the first will be returned. This method will ignore unrecognized object classes.This method uses the default schema for decoding the object class attribute values.
- Parameters:
entry- The entry whose structural object class is required.- Returns:
- The structural object class associated with the provided entry,
or
nullif none was found.
-
getStructuralObjectClass
public static ObjectClass getStructuralObjectClass(Entry entry, Schema schema)
Returns the structural object class associated with the provided entry, ornullif none was found. If the entry contains multiple structural object classes then the first will be returned. This method will ignore unrecognized object classes.- Parameters:
entry- The entry whose structural object class is required.schema- The schema which should be used for decoding the object class attribute values.- Returns:
- The structural object class associated with the provided entry,
or
nullif none was found.
-
isSubEntry
public static boolean isSubEntry(Entry entry)
Returns whether the provided entry is a sub entry.- Parameters:
entry- The entry to be checked.- Returns:
trueif the entry is a sub entry,falseotherwise.
-
makeEntry
public static Entry makeEntry(String... ldifLines)
Builds an entry from the provided lines of LDIF.Sample usage:
Entry john = makeEntry( "dn: cn=John Smith,dc=example,dc=com", "objectclass: inetorgperson", "cn: John Smith", "sn: Smith", "givenname: John");
- Parameters:
ldifLines- LDIF lines that contains entry definition.- Returns:
- an entry
- Throws:
LocalizedIllegalArgumentException- IfldifLinesdid not contain an LDIF entry, or contained multiple entries, or contained malformed LDIF, or if the entry could not be decoded using the default schema.NullPointerException- IfldifLineswasnull.
-
makeEntries
public static List<Entry> makeEntries(String... ldifLines)
Builds a list of entries from the provided lines of LDIF.Sample usage:
List<Entry> smiths = TestCaseUtils.makeEntries( "dn: cn=John Smith,dc=example,dc=com", "objectclass: inetorgperson", "cn: John Smith", "sn: Smith", "givenname: John", "", "dn: cn=Jane Smith,dc=example,dc=com", "objectclass: inetorgperson", "cn: Jane Smith", "sn: Smith", "givenname: Jane");
- Parameters:
ldifLines- LDIF lines that contains entries definition. Entries are separated by an empty string:"".- Returns:
- a non empty list of entries
- Throws:
LocalizedIllegalArgumentException- IfldifLinesdid not contain LDIF entries, or contained malformed LDIF, or if the entries could not be decoded using the default schema.NullPointerException- IfldifLineswasnull.
-
modifyEntry
public static Entry modifyEntry(Entry entry, Modification change) throws LdapException
Applies the provided modification to an entry. This method implements "permissive" modify semantics, ignoring attempts to add duplicate values or attempts to remove values which do not exist.- Parameters:
entry- The entry to be modified.change- The modification to be applied to the entry.- Returns:
- A reference to the updated entry.
- Throws:
LdapException- If an error occurred while performing the change such as an attempt to increment a value which is not a number. The entry will not have been modified.
-
modifyEntry
public static Entry modifyEntry(Entry entry, Modification change, Collection<? super ByteString> conflictingValues) throws LdapException
Applies the provided modification to an entry. This method implements "permissive" modify semantics, recording attempts to add duplicate values or attempts to remove values which do not exist in the provided collection if provided.- Parameters:
entry- The entry to be modified.change- The modification to be applied to the entry.conflictingValues- A collection into which duplicate or missing values will be added, ornullif conflicting values should not be saved.- Returns:
- A reference to the updated entry.
- Throws:
LdapException- If an error occurred while performing the change such as an attempt to increment a value which is not a number. The entry will not have been modified.
-
modifyEntry
public static Entry modifyEntry(Entry entry, ModifyRequest changes) throws LdapException
Applies the provided modification request to an entry. This method will utilize "permissive" modify semantics if the request contains thePermissiveModifyRequestControl.- Parameters:
entry- The entry to be modified.changes- The modification request to be applied to the entry.- Returns:
- A reference to the updated entry.
- Throws:
LdapException- If an error occurred while performing the changes such as an attempt to add duplicate values, remove values which do not exist, or increment a value which is not a number. The entry may have been modified.
-
modifyEntryPermissive
public static Entry modifyEntryPermissive(Entry entry, Collection<Modification> changes) throws LdapException
Applies the provided modifications to an entry using "permissive" modify semantics.- Parameters:
entry- The entry to be modified.changes- The modification request to be applied to the entry.- Returns:
- A reference to the updated entry.
- Throws:
LdapException- If an error occurred while performing the changes such as an attempt to increment a value which is not a number. The entry may have been modified.
-
modifyEntryStrict
public static Entry modifyEntryStrict(Entry entry, Collection<Modification> changes) throws LdapException
Applies the provided modifications to an entry using "strict" modify semantics. Attempts to add duplicate values or attempts to remove values which do not exist will cause the update to fail.- Parameters:
entry- The entry to be modified.changes- The modification request to be applied to the entry.- Returns:
- A reference to the updated entry.
- Throws:
LdapException- If an error occurred while performing the changes such as an attempt to add duplicate values, remove values which do not exist, or increment a value which is not a number. The entry may have been modified.
-
toLdif
public static String toLdif(Entry entry)
Returns the LDIF representation ofentry. All attributes will be included and no wrapping will be performed. This method can be useful when debugging applications.- Parameters:
entry- The entry to be converted to LDIF.- Returns:
- The LDIF representation of
entry.
-
unmodifiableEntry
public static Entry unmodifiableEntry(Entry entry)
Returns a read-only view ofentryand its attributes. Query operations on the returned entry and its attributes "read-through" to the underlying entry or attribute, and attempts to modify the returned entry and its attributes either directly or indirectly via an iterator result in anUnsupportedOperationException.- Parameters:
entry- The entry for which a read-only view is to be returned.- Returns:
- A read-only view of
entry. - Throws:
NullPointerException- Ifentrywasnull.
-
copyOnWriteEntry
public static Entry copyOnWriteEntry(Entry entry, Function<Entry,Entry> copyConstructor)
Returns a shallow copy-on-write view ofentry. Query operations on the returned entry and its attributes "read-through" to the underlying entry or attribute. Attempts to add, replace, or remove attributes result in the entry being lazily copied. Attribute iterables, such as those returned byEntry.getAllAttributes()are read-only (do not support removal).- Parameters:
entry- The entry for which a copy-on-write view is to be returned.copyConstructor- The copy constructor for lazily copying the entry.- Returns:
- A copy-on-write view of
entry. - Throws:
NullPointerException- Ifentrywasnull.
-
nullEntry
public static Entry nullEntry()
Returns a read-only empty entry having the empty distinguished name.Update attempts on the returned entry will be ignored.
All
attribute parsingattempts performed on this entry will return anempty attribute. Hence, using this factory can be useful to prevent null checks in client code.- Returns:
- The empty entry.
-
nullEntry
public static Entry nullEntry(Dn dn)
Returns a read-only empty entry having the provided distinguished name.Update attempts on the returned entry will be ignored.
All
attribute parsingattempts performed on this entry will return anempty attribute. Hence, using this factory can be useful to prevent null checks in client code.- Parameters:
dn- The entry distinguished name.- Returns:
- The empty entry.
-
-