directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r871782 - in /websites/staging/directory/trunk/content: ./ api/user-guide/6.12-entry.html
Date Mon, 29 Jul 2013 23:44:34 GMT
Author: buildbot
Date: Mon Jul 29 23:44:34 2013
New Revision: 871782

Log:
Staging update by buildbot for directory

Modified:
    websites/staging/directory/trunk/content/   (props changed)
    websites/staging/directory/trunk/content/api/user-guide/6.12-entry.html

Propchange: websites/staging/directory/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Mon Jul 29 23:44:34 2013
@@ -1 +1 @@
-1508227
+1508245

Modified: websites/staging/directory/trunk/content/api/user-guide/6.12-entry.html
==============================================================================
--- websites/staging/directory/trunk/content/api/user-guide/6.12-entry.html (original)
+++ websites/staging/directory/trunk/content/api/user-guide/6.12-entry.html Mon Jul 29 23:44:34 2013
@@ -338,352 +338,326 @@
 </pre></div>
 
 
-<DIV class="" 
-{note:title=Warning !}
+<DIV class="note" markdown="1">
+*Warning !*
 When manipulating a schema agnostic *Entry*, do not expect that the attribute type will be recognized if you inject schema aware attributes.
 </DIV>
 
-    :::Java
-    @Test
-    public void testEntryAddAtValue() throws LdapException
-    {
-        Entry entry = new DefaultEntry( 
-            "dc=example, dc=com",
-            "objectClass: top",
-            "objectClass: person",
-            "sn: test" );
-
-        assertFalse( entry.containsAttribute( "cn" ) );
-
-        // Add the new attribute
-        entry.add( "cn", "test" );
-
-        assertTrue( entry.contains( "cn", "test" ) );
-
-        // Try to add a second value
-        entry.add( atCn, "A  second  test" );
-
-        // Both values must be present
-        assertTrue( entry.contains( "cn", "test" ) );
-        assertTrue( entry.contains( "2.5.4.3", "a second test" ) );
-        assertFalse( entry.contains( "cn", "A  second  test" ) );
-    }
-
-##### put() methods
-
-The big difference with the _add_ method is that the attribute is not added, it will replace an existing one. let's see with an example :
-
-    :::Java
-    @Test
-    public void testEntryPutAttribute() throws LdapException
-    {
-        Entry entry = new DefaultEntry( 
-            schemaManager, 
-            "dc=example, dc=com",
-            "objectClass: top",
-            "objectClass: person",
-            "sn: test" );
-
-        assertFalse( entry.containsAttribute( "cn" ) );
-
-        // Add the new attribute
-        entry.put( "cn", "test" );
-
-        assertTrue( entry.contains( "cn", "test" ) );
-
-        // Try to add a second value
-        entry.put( "cn", "test2" );
-
-        // Both values must be present
-        assertFalse( entry.contains( "cn", "test", "test2" ) );
-        assertFalse( entry.contains( "cn", "test" ) );
-        assertTrue( entry.contains( "cn", "test2" ) );
-    }
-
-### Removing Attributes
-
-We can remove either an attribute having a specific value, or an entire attribute. In order to remove a complete attribute, you just have to provide the attribute's name, and use the _removeAttributes_ method.
-
-Here are some example for both usages :
-
-    :::Java
-    @Test
-    public void testRemoveAttribute() throws LdapException
-    {
-        Entry entry = new DefaultEntry( 
-            schemaManager,
-            "dc=example, dc=com",
-            "objectClass: top",
-            "objectClass: person",
-            "sn: test",
-            "cn: test1",
-            "cn: test2",
-            "cn: test3" );
-
-        assertTrue( entry.contains( "cn", "test1", "test2", "test3" ) );
-
-        // Remove the "test2" value
-        entry.remove( "cn", "test2" );
-
-        assertTrue( entry.contains( "cn", "test1", "test3" ) );
-        assertFalse( entry.contains( "cn", "test2" ) );
-
-        // Try to remove the full attribute
-        entry.removeAttributes( "cn" );
-
-        assertFalse( entry.containsAttribute( "cn" ) );
-    }
-
-#### Storing a Dn
-
-It's also possible to store a new _Dn_ into the Entry, using the _setDn() method. It will replace an existing _Dn_ This method takes either a _Dn_ instance, or a _String_.
-
-## Attribute data access methods
-
-The *API* provides convenient methods to access the *Entry* content, and to check if it contains some attributes or some values. We will shortly expose those methods in the following paragraphs.
-
-### Contains method
-The _contains_ and _containsAttributes_ methods check that the *Entry* contain a couple of <attributeType/values> for the first set of methods, and for the existence of a specific attribute for the second method.
-
-One can check for the existence of a specific value for a given attribute, or even for multiple values for a specific attribute. Let's see the _contains_ method in action:
-
-    :::Java
-    @Test
-    public void testContains() throws LdapException
-    {
-        Entry entry = new DefaultEntry( 
-            schemaManager,
-            "dc=example, dc=com",
-            "objectClass: top",
-            "objectClass: person",
-            "sn: test",
-            "cn: test1",
-            "cn: test2",
-            "cn: test3" );
-
-        assertTrue( entry.containsAttribute( "cn", "sn" ) );
-        assertTrue( entry.contains( "cn", "test1", "test2", "test3" ) );
-        assertTrue( entry.contains( "cn", "test1" ) );
-
-        // The value does not exist for the "cn" attribute
-        assertFalse( entry.contains( "cn", "test4" ) );
-    }
-
-#### get(AttributeType) and get(String)
-
-Returns the _Attribute_ having the given name if it exists. The following test demonstrates its usage:
-
-    :::Java
-    @Test
-    public void testGet() throws LdapException
-    {
-        Entry entry = new DefaultEntry( 
-            schemaManager,
-            "dc=example, dc=com",
-            "objectClass: top",
-            "objectClass: person",
-            "sn: test",
-            "cn: test1",
-            "cn: test2",
-            "cn: test3" );
-
-        // With an attribute's name
-        assertNotNull( entry.get( "cn" ) );
-        assertTrue( entry.get( "cn" ).contains( "test1", "test2", "test3" ) );
-
-        // With an AttributeType
-        assertNotNull( entry.get( atSn ) );
-        assertTrue( entry.get( atSn ).contains( "test" ) );
-    }
-
-#### getAttributeTypes()
-
-This method returns the list of _AttributeTypes_ stored into the *Entry*.
-
-{note:title=Be careful !}
-This method is only valuable if the *Entry* is schema aware !
-{note}
-
-Here is an example of usage:
-
-    :::Java
-    @Test
-    public void testGetAttributeTypes() throws LdapException
-    {
-        Entry entry = new DefaultEntry( 
-            schemaManager,
-            "cn=example, dc=com", 
-            "objectClass: top",
-            "objectClass: person",
-            "cn: example",
-            "sn: test"
-            );
-
-        for ( AttributeType attr : entry.getAttributeTypes() )
-        {
-            System.out.println( attr.getName() );
-        }
-    }
-
-This code produces the following output:
-
-    :::Java
-    sn
-    objectClass
-    cn
-
-#### getDn()
-
-This method returns the *Entry*'s _Dn_.
-
-#### hasObjectClass methods
-
-The _hasObjectClass()_ methods are used to discover if an *Entry* has a specific _ObjectClass_. This is a convenient method, as it's possible to do the same thing with a _contains()_ call, but with one less parameter (you don't have to provide the _"ObjectClass"_ as a first parameter).
-
-Here is an example using the two existing methods:
-
-    :::Java
-    @Test
-    public void testHasObjectClass() throws LdapException
-    {
-        Entry entry = new DefaultEntry( 
-            schemaManager,
-            "cn=example, dc=com", 
-            "objectClass: top",
-            "objectClass: person",
-            "cn: example",
-            "sn: test"
-            );
-
-        // Test the presence
-        assertTrue( entry.hasObjectClass( "person", " TOP " ) );
-        assertFalse( entry.hasObjectClass( "domain ", "TOP" ) );
-        assertTrue( entry.hasObjectClass( "Person " ) );
-
-        // Same test, but with Attributes
-        Attribute oc1 = new DefaultAttribute( atObjectClass, "TOP ", "person" );
-        Attribute oc2 = new DefaultAttribute( atObjectClass, "person " );
-        Attribute oc3 = new DefaultAttribute( atObjectClass, "TOP", "domain" );
-
-        assertTrue( entry.hasObjectClass( oc1, oc2 ) );
-        assertFalse( entry.hasObjectClass( oc1, oc3 ) );
-    }
-
-Obviously, dealing with a schema agnostic *Entry*, those methods are more strict. You have to use the exact ObjectClasses case sensitive trimmed names (in the previous example, we can use upper cased names, even with spaces around the names).
-
-Also note that the _hasObjectClass_ method used with _AttributeType_ does not work on a schema agnostic entry.
-
-## Miscellaneous methods
-We also have some other methods which can be used on an *Entry*. Here is a list of those methods.
-
-#### clear()
-This method removes all the added _Attributes_ from this *Entry*. The _Dn_ remains the same.
-
-#### clone()
-Creates a copy of the current *Entry*. All the _Attributes_ are also cloned.
-
-#### iterator()
-Allows an iteration over all the _Attributes_. The following examples shows how this can be used:
-
-    :::Java
-    @Test
-    public void testIterator() throws LdapException
-    {
-        Entry entry = new DefaultEntry( 
-            "cn=example, dc=com", 
-            "objectClass: top",
-            "objectClass: person",
-            "cn: example",
-            "sn: test"
-            );
-
-        for ( Attribute attribute : entry )
-        {
-            System.out.println( "Attribute : \n" + attribute.toString() );
-        }
-    }
-
-This produces the following output:
-
-    :::Java
-    Attribute : 
-        sn: test
-
-    Attribute : 
-        cn: example
-
-    Attribute : 
-        objectclass: top
-        objectclass: person
-
-Note that the _Attribute_ order is not guaranteed.
-
-#### isSchemaAware()
-
-Tells if the ¨*Entry* has an associated _SchemaManager_.
-
-#### size()
-Returns the number of _Attribute_ stored in the *Entry*.
-
-#### equals(Object)
-Check if two *Entries* are equal or not. It's important to understand that depending on whether the entry is schema aware or not, the comparison will be processed differently. Typically, the attribute's name must be equals when they have been trimmed and lower cased if the entry is not schema aware, and we can't compare an attribute named 'cn' with another one named '2.5.4.3' in this case (the *Entry* must be schema aware to allow such comparison). More important, the values *must* be identical (same casing, same spaces) in this case.
-The attribute's values order is irrelevant.
-
-Here are one example with a schema agnostic *Entry*:
-
-    :::Java
-    @Test
-    public void testEntryEquals() throws LdapException
-    {
-        Entry entry = new DefaultEntry( 
-            "dc=example, dc=com",
-            "objectClass: top",
-            "objectClass: person",
-            "sn: test",
-            "cn: test1",
-            "cn: test2",
-            "cn: test3" );
-
-        Entry entry2 = new DefaultEntry( 
-            "dc=example, dc=com",
-            "objectClass: top",
-            "objectClass: person",
-            "sn: test",
-            "cn: test2",
-            "CN: test1",
-            "cn: test3" );
-
-        assertEquals( entry, entry2 );
-    }
-
-and another example with a schema aware *Entry*:
-
-    :::Java
-    @Test
-    public void testSchemaAwayeEntryEquals() throws LdapException
-    {
-        Entry entry = new DefaultEntry( 
-            schemaManager,
-            "dc=example, dc=com",
-            "objectClass: top",
-            "objectClass: person",
-            "sn: test",
-            "cn: test1",
-            "cn: test2",
-            "cn: test3" );
-
-        Entry entry2 = new DefaultEntry( 
-            schemaManager,
-            "dc=example,dc=com",
-            "objectClass: TOP",
-            "objectClass: person",
-            "sn: Test",
-            "cn: Test2",
-            "2.5.4.3: test1",
-            "CommonName: test3" );
+<div class="codehilite"><pre><span class="nd">@Test</span>
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">testEntryAddAtValue</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">LdapException</span>
+<span class="o">{</span>
+    <span class="n">Entry</span> <span class="n">entry</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultEntry</span><span class="o">(</span> 
+        <span class="s">&quot;dc=example, dc=com&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: top&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: person&quot;</span><span class="o">,</span>
+        <span class="s">&quot;sn: test&quot;</span> <span class="o">);</span>
+
+    <span class="n">assertFalse</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">containsAttribute</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span> <span class="o">)</span> <span class="o">);</span>
+
+    <span class="c1">// Add the new attribute</span>
+    <span class="n">entry</span><span class="o">.</span><span class="na">add</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test&quot;</span> <span class="o">);</span>
+
+    <span class="n">assertTrue</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test&quot;</span> <span class="o">)</span> <span class="o">);</span>
+
+    <span class="c1">// Try to add a second value</span>
+    <span class="n">entry</span><span class="o">.</span><span class="na">add</span><span class="o">(</span> <span class="n">atCn</span><span class="o">,</span> <span class="s">&quot;A  second  test&quot;</span> <span class="o">);</span>
+
+    <span class="c1">// Both values must be present</span>
+    <span class="n">assertTrue</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test&quot;</span> <span class="o">)</span> <span class="o">);</span>
+    <span class="n">assertTrue</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;2.5.4.3&quot;</span><span class="o">,</span> <span class="s">&quot;a second test&quot;</span> <span class="o">)</span> <span class="o">);</span>
+    <span class="n">assertFalse</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;A  second  test&quot;</span> <span class="o">)</span> <span class="o">);</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<h5 id="put-methods">put() methods</h5>
+<p>The big difference with the <em>add</em> method is that the attribute is not added, it will replace an existing one. let's see with an example :</p>
+<div class="codehilite"><pre><span class="nd">@Test</span>
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">testEntryPutAttribute</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">LdapException</span>
+<span class="o">{</span>
+    <span class="n">Entry</span> <span class="n">entry</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultEntry</span><span class="o">(</span> 
+        <span class="n">schemaManager</span><span class="o">,</span> 
+        <span class="s">&quot;dc=example, dc=com&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: top&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: person&quot;</span><span class="o">,</span>
+        <span class="s">&quot;sn: test&quot;</span> <span class="o">);</span>
+
+    <span class="n">assertFalse</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">containsAttribute</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span> <span class="o">)</span> <span class="o">);</span>
+
+    <span class="c1">// Add the new attribute</span>
+    <span class="n">entry</span><span class="o">.</span><span class="na">put</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test&quot;</span> <span class="o">);</span>
+
+    <span class="n">assertTrue</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test&quot;</span> <span class="o">)</span> <span class="o">);</span>
+
+    <span class="c1">// Try to add a second value</span>
+    <span class="n">entry</span><span class="o">.</span><span class="na">put</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test2&quot;</span> <span class="o">);</span>
+
+    <span class="c1">// Both values must be present</span>
+    <span class="n">assertFalse</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test&quot;</span><span class="o">,</span> <span class="s">&quot;test2&quot;</span> <span class="o">)</span> <span class="o">);</span>
+    <span class="n">assertFalse</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test&quot;</span> <span class="o">)</span> <span class="o">);</span>
+    <span class="n">assertTrue</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test2&quot;</span> <span class="o">)</span> <span class="o">);</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<h3 id="removing-attributes">Removing Attributes</h3>
+<p>We can remove either an attribute having a specific value, or an entire attribute. In order to remove a complete attribute, you just have to provide the attribute's name, and use the <em>removeAttributes</em> method.</p>
+<p>Here are some example for both usages :</p>
+<div class="codehilite"><pre><span class="nd">@Test</span>
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">testRemoveAttribute</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">LdapException</span>
+<span class="o">{</span>
+    <span class="n">Entry</span> <span class="n">entry</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultEntry</span><span class="o">(</span> 
+        <span class="n">schemaManager</span><span class="o">,</span>
+        <span class="s">&quot;dc=example, dc=com&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: top&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: person&quot;</span><span class="o">,</span>
+        <span class="s">&quot;sn: test&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test1&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test2&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test3&quot;</span> <span class="o">);</span>
+
+    <span class="n">assertTrue</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test1&quot;</span><span class="o">,</span> <span class="s">&quot;test2&quot;</span><span class="o">,</span> <span class="s">&quot;test3&quot;</span> <span class="o">)</span> <span class="o">);</span>
+
+    <span class="c1">// Remove the &quot;test2&quot; value</span>
+    <span class="n">entry</span><span class="o">.</span><span class="na">remove</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test2&quot;</span> <span class="o">);</span>
+
+    <span class="n">assertTrue</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test1&quot;</span><span class="o">,</span> <span class="s">&quot;test3&quot;</span> <span class="o">)</span> <span class="o">);</span>
+    <span class="n">assertFalse</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test2&quot;</span> <span class="o">)</span> <span class="o">);</span>
+
+    <span class="c1">// Try to remove the full attribute</span>
+    <span class="n">entry</span><span class="o">.</span><span class="na">removeAttributes</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span> <span class="o">);</span>
+
+    <span class="n">assertFalse</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">containsAttribute</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span> <span class="o">)</span> <span class="o">);</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<h4 id="storing-a-dn">Storing a Dn</h4>
+<p>It's also possible to store a new <em>Dn</em> into the Entry, using the <em>setDn() method. It will replace an existing _Dn</em> This method takes either a <em>Dn</em> instance, or a <em>String</em>.</p>
+<h2 id="attribute-data-access-methods">Attribute data access methods</h2>
+<p>The <em>API</em> provides convenient methods to access the <em>Entry</em> content, and to check if it contains some attributes or some values. We will shortly expose those methods in the following paragraphs.</p>
+<h3 id="contains-method">Contains method</h3>
+<p>The <em>contains</em> and <em>containsAttributes</em> methods check that the <em>Entry</em> contain a couple of <attributeType/values> for the first set of methods, and for the existence of a specific attribute for the second method.</p>
+<p>One can check for the existence of a specific value for a given attribute, or even for multiple values for a specific attribute. Let's see the <em>contains</em> method in action:</p>
+<div class="codehilite"><pre><span class="nd">@Test</span>
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">testContains</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">LdapException</span>
+<span class="o">{</span>
+    <span class="n">Entry</span> <span class="n">entry</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultEntry</span><span class="o">(</span> 
+        <span class="n">schemaManager</span><span class="o">,</span>
+        <span class="s">&quot;dc=example, dc=com&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: top&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: person&quot;</span><span class="o">,</span>
+        <span class="s">&quot;sn: test&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test1&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test2&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test3&quot;</span> <span class="o">);</span>
+
+    <span class="n">assertTrue</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">containsAttribute</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;sn&quot;</span> <span class="o">)</span> <span class="o">);</span>
+    <span class="n">assertTrue</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test1&quot;</span><span class="o">,</span> <span class="s">&quot;test2&quot;</span><span class="o">,</span> <span class="s">&quot;test3&quot;</span> <span class="o">)</span> <span class="o">);</span>
+    <span class="n">assertTrue</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test1&quot;</span> <span class="o">)</span> <span class="o">);</span>
+
+    <span class="c1">// The value does not exist for the &quot;cn&quot; attribute</span>
+    <span class="n">assertFalse</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span><span class="o">,</span> <span class="s">&quot;test4&quot;</span> <span class="o">)</span> <span class="o">);</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<h4 id="getattributetype-and-getstring">get(AttributeType) and get(String)</h4>
+<p>Returns the <em>Attribute</em> having the given name if it exists. The following test demonstrates its usage:</p>
+<div class="codehilite"><pre><span class="nd">@Test</span>
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">testGet</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">LdapException</span>
+<span class="o">{</span>
+    <span class="n">Entry</span> <span class="n">entry</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultEntry</span><span class="o">(</span> 
+        <span class="n">schemaManager</span><span class="o">,</span>
+        <span class="s">&quot;dc=example, dc=com&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: top&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: person&quot;</span><span class="o">,</span>
+        <span class="s">&quot;sn: test&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test1&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test2&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test3&quot;</span> <span class="o">);</span>
+
+    <span class="c1">// With an attribute&#39;s name</span>
+    <span class="n">assertNotNull</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">get</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span> <span class="o">)</span> <span class="o">);</span>
+    <span class="n">assertTrue</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">get</span><span class="o">(</span> <span class="s">&quot;cn&quot;</span> <span class="o">).</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;test1&quot;</span><span class="o">,</span> <span class="s">&quot;test2&quot;</span><span class="o">,</span> <span class="s">&quot;test3&quot;</span> <span class="o">)</span> <span class="o">);</span>
+
+    <span class="c1">// With an AttributeType</span>
+    <span class="n">assertNotNull</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">get</span><span class="o">(</span> <span class="n">atSn</span> <span class="o">)</span> <span class="o">);</span>
+    <span class="n">assertTrue</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">get</span><span class="o">(</span> <span class="n">atSn</span> <span class="o">).</span><span class="na">contains</span><span class="o">(</span> <span class="s">&quot;test&quot;</span> <span class="o">)</span> <span class="o">);</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<h4 id="getattributetypes">getAttributeTypes()</h4>
+<p>This method returns the list of <em>AttributeTypes</em> stored into the <em>Entry</em>.</p>
+<p>{note:title=Be careful !}
+This method is only valuable if the <em>Entry</em> is schema aware !
+{note}</p>
+<p>Here is an example of usage:</p>
+<div class="codehilite"><pre><span class="nd">@Test</span>
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">testGetAttributeTypes</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">LdapException</span>
+<span class="o">{</span>
+    <span class="n">Entry</span> <span class="n">entry</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultEntry</span><span class="o">(</span> 
+        <span class="n">schemaManager</span><span class="o">,</span>
+        <span class="s">&quot;cn=example, dc=com&quot;</span><span class="o">,</span> 
+        <span class="s">&quot;objectClass: top&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: person&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: example&quot;</span><span class="o">,</span>
+        <span class="s">&quot;sn: test&quot;</span>
+        <span class="o">);</span>
+
+    <span class="k">for</span> <span class="o">(</span> <span class="n">AttributeType</span> <span class="n">attr</span> <span class="o">:</span> <span class="n">entry</span><span class="o">.</span><span class="na">getAttributeTypes</span><span class="o">()</span> <span class="o">)</span>
+    <span class="o">{</span>
+        <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span> <span class="n">attr</span><span class="o">.</span><span class="na">getName</span><span class="o">()</span> <span class="o">);</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
 
-        assertEquals( entry, entry2 );
-    }
+
+<p>This code produces the following output:</p>
+<div class="codehilite"><pre><span class="n">sn</span>
+<span class="n">objectClass</span>
+<span class="n">cn</span>
+</pre></div>
+
+
+<h4 id="getdn">getDn()</h4>
+<p>This method returns the <em>Entry</em>'s <em>Dn</em>.</p>
+<h4 id="hasobjectclass-methods">hasObjectClass methods</h4>
+<p>The <em>hasObjectClass()</em> methods are used to discover if an <em>Entry</em> has a specific <em>ObjectClass</em>. This is a convenient method, as it's possible to do the same thing with a <em>contains()</em> call, but with one less parameter (you don't have to provide the <em>"ObjectClass"</em> as a first parameter).</p>
+<p>Here is an example using the two existing methods:</p>
+<div class="codehilite"><pre><span class="nd">@Test</span>
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">testHasObjectClass</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">LdapException</span>
+<span class="o">{</span>
+    <span class="n">Entry</span> <span class="n">entry</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultEntry</span><span class="o">(</span> 
+        <span class="n">schemaManager</span><span class="o">,</span>
+        <span class="s">&quot;cn=example, dc=com&quot;</span><span class="o">,</span> 
+        <span class="s">&quot;objectClass: top&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: person&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: example&quot;</span><span class="o">,</span>
+        <span class="s">&quot;sn: test&quot;</span>
+        <span class="o">);</span>
+
+    <span class="c1">// Test the presence</span>
+    <span class="n">assertTrue</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">hasObjectClass</span><span class="o">(</span> <span class="s">&quot;person&quot;</span><span class="o">,</span> <span class="s">&quot; TOP &quot;</span> <span class="o">)</span> <span class="o">);</span>
+    <span class="n">assertFalse</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">hasObjectClass</span><span class="o">(</span> <span class="s">&quot;domain &quot;</span><span class="o">,</span> <span class="s">&quot;TOP&quot;</span> <span class="o">)</span> <span class="o">);</span>
+    <span class="n">assertTrue</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">hasObjectClass</span><span class="o">(</span> <span class="s">&quot;Person &quot;</span> <span class="o">)</span> <span class="o">);</span>
+
+    <span class="c1">// Same test, but with Attributes</span>
+    <span class="n">Attribute</span> <span class="n">oc1</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultAttribute</span><span class="o">(</span> <span class="n">atObjectClass</span><span class="o">,</span> <span class="s">&quot;TOP &quot;</span><span class="o">,</span> <span class="s">&quot;person&quot;</span> <span class="o">);</span>
+    <span class="n">Attribute</span> <span class="n">oc2</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultAttribute</span><span class="o">(</span> <span class="n">atObjectClass</span><span class="o">,</span> <span class="s">&quot;person &quot;</span> <span class="o">);</span>
+    <span class="n">Attribute</span> <span class="n">oc3</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultAttribute</span><span class="o">(</span> <span class="n">atObjectClass</span><span class="o">,</span> <span class="s">&quot;TOP&quot;</span><span class="o">,</span> <span class="s">&quot;domain&quot;</span> <span class="o">);</span>
+
+    <span class="n">assertTrue</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">hasObjectClass</span><span class="o">(</span> <span class="n">oc1</span><span class="o">,</span> <span class="n">oc2</span> <span class="o">)</span> <span class="o">);</span>
+    <span class="n">assertFalse</span><span class="o">(</span> <span class="n">entry</span><span class="o">.</span><span class="na">hasObjectClass</span><span class="o">(</span> <span class="n">oc1</span><span class="o">,</span> <span class="n">oc3</span> <span class="o">)</span> <span class="o">);</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>Obviously, dealing with a schema agnostic <em>Entry</em>, those methods are more strict. You have to use the exact ObjectClasses case sensitive trimmed names (in the previous example, we can use upper cased names, even with spaces around the names).</p>
+<p>Also note that the <em>hasObjectClass</em> method used with <em>AttributeType</em> does not work on a schema agnostic entry.</p>
+<h2 id="miscellaneous-methods">Miscellaneous methods</h2>
+<p>We also have some other methods which can be used on an <em>Entry</em>. Here is a list of those methods.</p>
+<h4 id="clear">clear()</h4>
+<p>This method removes all the added <em>Attributes</em> from this <em>Entry</em>. The <em>Dn</em> remains the same.</p>
+<h4 id="clone">clone()</h4>
+<p>Creates a copy of the current <em>Entry</em>. All the <em>Attributes</em> are also cloned.</p>
+<h4 id="iterator">iterator()</h4>
+<p>Allows an iteration over all the <em>Attributes</em>. The following examples shows how this can be used:</p>
+<div class="codehilite"><pre><span class="nd">@Test</span>
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">testIterator</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">LdapException</span>
+<span class="o">{</span>
+    <span class="n">Entry</span> <span class="n">entry</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultEntry</span><span class="o">(</span> 
+        <span class="s">&quot;cn=example, dc=com&quot;</span><span class="o">,</span> 
+        <span class="s">&quot;objectClass: top&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: person&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: example&quot;</span><span class="o">,</span>
+        <span class="s">&quot;sn: test&quot;</span>
+        <span class="o">);</span>
+
+    <span class="k">for</span> <span class="o">(</span> <span class="n">Attribute</span> <span class="n">attribute</span> <span class="o">:</span> <span class="n">entry</span> <span class="o">)</span>
+    <span class="o">{</span>
+        <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span> <span class="s">&quot;Attribute : \n&quot;</span> <span class="o">+</span> <span class="n">attribute</span><span class="o">.</span><span class="na">toString</span><span class="o">()</span> <span class="o">);</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>This produces the following output:</p>
+<div class="codehilite"><pre><span class="n">Attribute</span> <span class="o">:</span> 
+    <span class="nl">sn:</span> <span class="n">test</span>
+
+<span class="n">Attribute</span> <span class="o">:</span> 
+    <span class="nl">cn:</span> <span class="n">example</span>
+
+<span class="n">Attribute</span> <span class="o">:</span> 
+    <span class="nl">objectclass:</span> <span class="n">top</span>
+    <span class="nl">objectclass:</span> <span class="n">person</span>
+</pre></div>
+
+
+<p>Note that the <em>Attribute</em> order is not guaranteed.</p>
+<h4 id="isschemaaware">isSchemaAware()</h4>
+<p>Tells if the ¨<em>Entry</em> has an associated <em>SchemaManager</em>.</p>
+<h4 id="size">size()</h4>
+<p>Returns the number of <em>Attribute</em> stored in the <em>Entry</em>.</p>
+<h4 id="equalsobject">equals(Object)</h4>
+<p>Check if two <em>Entries</em> are equal or not. It's important to understand that depending on whether the entry is schema aware or not, the comparison will be processed differently. Typically, the attribute's name must be equals when they have been trimmed and lower cased if the entry is not schema aware, and we can't compare an attribute named 'cn' with another one named '2.5.4.3' in this case (the <em>Entry</em> must be schema aware to allow such comparison). More important, the values <em>must</em> be identical (same casing, same spaces) in this case.
+The attribute's values order is irrelevant.</p>
+<p>Here are one example with a schema agnostic <em>Entry</em>:</p>
+<div class="codehilite"><pre><span class="nd">@Test</span>
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">testEntryEquals</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">LdapException</span>
+<span class="o">{</span>
+    <span class="n">Entry</span> <span class="n">entry</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultEntry</span><span class="o">(</span> 
+        <span class="s">&quot;dc=example, dc=com&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: top&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: person&quot;</span><span class="o">,</span>
+        <span class="s">&quot;sn: test&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test1&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test2&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test3&quot;</span> <span class="o">);</span>
+
+    <span class="n">Entry</span> <span class="n">entry2</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultEntry</span><span class="o">(</span> 
+        <span class="s">&quot;dc=example, dc=com&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: top&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: person&quot;</span><span class="o">,</span>
+        <span class="s">&quot;sn: test&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test2&quot;</span><span class="o">,</span>
+        <span class="s">&quot;CN: test1&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test3&quot;</span> <span class="o">);</span>
+
+    <span class="n">assertEquals</span><span class="o">(</span> <span class="n">entry</span><span class="o">,</span> <span class="n">entry2</span> <span class="o">);</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>and another example with a schema aware <em>Entry</em>:</p>
+<div class="codehilite"><pre><span class="nd">@Test</span>
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">testSchemaAwayeEntryEquals</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">LdapException</span>
+<span class="o">{</span>
+    <span class="n">Entry</span> <span class="n">entry</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultEntry</span><span class="o">(</span> 
+        <span class="n">schemaManager</span><span class="o">,</span>
+        <span class="s">&quot;dc=example, dc=com&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: top&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: person&quot;</span><span class="o">,</span>
+        <span class="s">&quot;sn: test&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test1&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test2&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: test3&quot;</span> <span class="o">);</span>
+
+    <span class="n">Entry</span> <span class="n">entry2</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultEntry</span><span class="o">(</span> 
+        <span class="n">schemaManager</span><span class="o">,</span>
+        <span class="s">&quot;dc=example,dc=com&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: TOP&quot;</span><span class="o">,</span>
+        <span class="s">&quot;objectClass: person&quot;</span><span class="o">,</span>
+        <span class="s">&quot;sn: Test&quot;</span><span class="o">,</span>
+        <span class="s">&quot;cn: Test2&quot;</span><span class="o">,</span>
+        <span class="s">&quot;2.5.4.3: test1&quot;</span><span class="o">,</span>
+        <span class="s">&quot;CommonName: test3&quot;</span> <span class="o">);</span>
+
+    <span class="n">assertEquals</span><span class="o">(</span> <span class="n">entry</span><span class="o">,</span> <span class="n">entry2</span> <span class="o">);</span>
+<span class="o">}</span>
+</pre></div>
 
 
     <div class="nav">



Mime
View raw message