h2. LdifEntry A LdifEntry is used to store an entry after it has been parsed from a *LDIF* String. We can use a *LDIF* entry to add a new entry, delete an existing one, move an entry or modify an entry (adding, removing or changing some attributes or value). In any case, a *LdifEntry* has a *[DIRAPI:Dn]*, plus some attributes. If we don't have a _changeType_ *[DIRAPI:AttributeType]* (this is a special attribute used to indicate that we are going t modify an existing entry), then the *LdifEntry* is a new entry. An *LdifEntry* can also have controls, if the special *[DIRAPI:AttributeType]* _controls_ is present. Comments will be ignored, and we won't keep them when we build a new *LdifEntry*. The special *[DIRAPI:AttributeType]* _version_ is not mandatory, it would break too many *LDIF* files generated by most of the existing *LDAP* servers. It's simply ignored for the moment. We use an _enum_ to store the change type : _ChangeType_. The possible values are the following : {code:java} public enum ChangeType { /** The Add changeType */ Add(0), /** The Modify changeType */ Modify(1), /** The ModDn changeType */ ModDn(2), /** The ModRdn changeType */ ModRdn(3), /** The Delete changeType */ Delete(4), /** A place-holder when we have no changeType */ None(-1); ... {code} h3. Constructors h4. _LdifEntry()_ Creates a simple *LdifEntry*, with no information into it. h4. _LdifEntry(String, ObjectÉ)_, _ _LdifEntry(Dn, ObjectÉ)_ Creates an entry with a *[DIRAPI:Dn]* and some attributes and values given in a *LDIF* format. Here is an example : {code:java} @Test public void testSimpleLdifEntry() throws Exception { String cn = "app1"; LdifEntry ldifEntry = new LdifEntry( "cn=app1,dc=apache,dc=org", "cn", cn, "objectClass: top", "objectClass: apApplication", "displayName: app1 ", "dependencies:", "envVars:" ); assertNotNull( ldifEntry ); assertTrue( ldifEntry.isLdifContent() ); assertEquals( "cn=app1,dc=apache,dc=org", ldifEntry.getDn().getName() ); Attribute attr = ldifEntry.get( "displayname" ); assertTrue( attr.contains( "app1" ) ); Attribute cnAttr = ldifEntry.get( "cn" ); assertTrue( cnAttr.contains( "app1" ) ); } {code} * _LdifEntry(Entry)_ Creates an *LdifEntry* from an *[DIRAPI:Entry]*. We won't have any change type for the created *LdifEntry*. If you use this *LdifEntry* and inject it into a *LDAP* server, a new entry will be created. h4. Getters We have a set of getters : * _get(String)_: Gets the attribute which name is given. * _getChangeType()_: Returns the change type. * _getControl(String)_: Returns the *[DIRAPI:Control]* with the specific *Oid*, if there is one in the *LdifEntry*. * _getControls()_: Returns the list of existing *[DIRAPI:Control]s* * _getDn()_: Returns the *LdifEntry* *[DIRAPI:Dn]* * _getEntry()_: Returns the stored entry, if any (this method will return null if the *LdifEntry* is used to encode a delete operation) * _getModifications()_: Returns the list of *[DIRAPI:Modification] applied in the *LdifEntry*, as a _List_ * _getModificationArray()_: Returns the list of *[DIRAPI:Modification] applied in the *LdifEntry*, as an array * _getNewRdn()_: If the *LdifEntry* encodes for a mve operation, gets the new name. * _getNewSuperior()_: If the *LdifEntry* encodes for a mve operation, gets the new Parent. h4. Modifying an LdifEntry We have a set of methods used to modify the current *LdifEntry* * _addAttribute(Attribute)_: Adds an attribute to the *LdifEntry* * _addAttribute(String, Object...)_: Adds an attribute with some values in the *LdifEntry* * _addControl(Control...)_: Adds a *[DIRAPI:Control]* to the *LdifEntry* * _addModification(Modification)_: Adds a *[DIRAPI:Modificaton]* to the *LdifEntry* * _addModification(ModificationOperation, Attribute)_: Adds a new modification to the *LdifEntry*, created from the operation and attribute. * _addModification(ModificationOperation, String, Object)_: Adds a new modification to the *LdifEntry*, created from the operation, attribute type and values. * _putAttribute(String, Object)_: Adds a new attribute and values in the *LdifEntry*. * _removeAttribute(String...)_: Remove a set of attributes from the *LdifEntry* * _setChangeType(ChangeType)_: Set the type of change we apply on the *LdifEntry*. * _setChangeType(String)_: Same method, but using the *ChangeType* name ( "Add", "Modify", "ModDn", "ModRdn", "Delete") * _setDeleteOldRdn(boolean)_: Sets the flag requesting for the deletion of the old Rdn when it's a move operation. * _setDn(Dn)_: Sets the *LdifEntry* *[DIRAPI:Dn]* * _setDn(String)_: Sets the *LdifEntry* *[DIRAPI:Dn]* * _setNewRdn(String)_: Sets the new *LdifEntry* name if it's a move operation. * _setNewSuperior(String)_: Sets the new *LdifEntry* parent if it's a move operation. h4. LdifEntry status We now have a set of methods used to get some status of the current *LdifEntry* : * _hasControls()_: Tells if the *LdifEntry* has some controls. * _isChangeAdd()_: Tells if the *LdifEntry* is a modification with an _Add_ operation. * _isChangeDelete()_: Tells if the *LdifEntry* is a modification with a _Delete_ operation. * _isChangeModDn()_: Tells if the *LdifEntry* is a modification with an _ModDn_ operation. * _isChangeModify()_: Tells if the *LdifEntry* is a modification with an _Modify_ operation. * _isChangeModRdn()_: Tells if the *LdifEntry* is a modification with an _ModRdn_ operation. * _isDeleteOldRdn()_: Tells if the old *[DIRAPI:Rdn]* should be deleted * _isEntry()_: Tells if the *LdifEntry* encodes for a simple entry addition * _isLdifChange()_: Tells if the *LdifEntry* encodes for a modify operation or a delete operation * _isLdifContent()_: Tells if the *LdifEntry* is not a change operation nor a delete operation. * _size()_: Gives the number of modifications if it's a change operation