Java Code Examples for org.apache.directory.api.ldap.model.entry.Entry#clone()

The following examples show how to use org.apache.directory.api.ldap.model.entry.Entry#clone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for clone()
 */
@Test
public void testClone() throws LdapException
{
    Entry entry1 = new DefaultEntry();

    Entry entry2 = entry1.clone();

    assertEquals( entry1, entry2 );
    entry2.setDn( exampleDn );

    assertEquals( Dn.EMPTY_DN, entry1.getDn() );

    entry1.setDn( exampleDn );
    entry2 = entry1.clone();
    assertEquals( entry1, entry2 );

    entry1.add( "objectClass", "top", "person" );
    entry1.add( "cn", "test1", "test2" );

    entry2 = entry1.clone();
    assertEquals( entry1, entry2 );

    entry1.add( "cn", "test3" );
    assertEquals( 2, entry2.get( "cn" ).size() );
    assertFalse( entry2.contains( "cn", "test3" ) );

    entry1.add( "sn", ( String ) null );
    assertFalse( entry2.containsAttribute( "sn" ) );
}
 
Example 2
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * Check that all the attribute's values which are Human Readable can be transformed
 * to valid String if they are stored as byte[], and that non Human Readable attributes
 * stored as String can be transformed to byte[]
 */
private void assertHumanReadable( Entry entry ) throws LdapException
{
    boolean isModified = false;

    Entry clonedEntry = null;

    // Loops on all attributes
    for ( Attribute attribute : entry )
    {
        AttributeType attributeType = attribute.getAttributeType();

        // If the attributeType is H-R, check all of its values
        if ( attributeType.getSyntax().isHumanReadable() )
        {
            isModified = checkHumanReadable( attribute );
        }
        else
        {
            isModified = checkNotHumanReadable( attribute );
        }

        // If we have a returned attribute, then we need to store it
        // into a new entry
        if ( isModified )
        {
            if ( clonedEntry == null )
            {
                clonedEntry = entry.clone();
            }

            // Switch the attributes
            clonedEntry.put( attribute );

            isModified = false;
        }
    }

    if ( clonedEntry != null )
    {
        entry = clonedEntry;
    }
}
 
Example 3
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * Check that all the attribute's values which are Human Readable can be transformed
 * to valid String if they are stored as byte[], and that non Human Readable attributes
 * stored as String can be transformed to byte[]
 */
private void assertHumanReadable( Entry entry ) throws LdapException
{
    boolean isModified = false;

    Entry clonedEntry = null;

    // Loops on all attributes
    for ( Attribute attribute : entry )
    {
        AttributeType attributeType = attribute.getAttributeType();

        // If the attributeType is H-R, check all of its values
        if ( attributeType.getSyntax().isHumanReadable() )
        {
            isModified = checkHumanReadable( attribute );
        }
        else
        {
            isModified = checkNotHumanReadable( attribute );
        }

        // If we have a returned attribute, then we need to store it
        // into a new entry
        if ( isModified )
        {
            if ( clonedEntry == null )
            {
                clonedEntry = entry.clone();
            }

            // Switch the attributes
            clonedEntry.put( attribute );

            isModified = false;
        }
    }

    if ( clonedEntry != null )
    {
        entry = clonedEntry;
    }
}