You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2008/08/29 00:41:00 UTC
svn commit: r690033 - in /directory:
apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/
shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/
shared/trunk/ldap/src/main/java/org/apache/directory/shar...
Author: elecharny
Date: Thu Aug 28 15:40:59 2008
New Revision: 690033
URL: http://svn.apache.org/viewvc?rev=690033&view=rev
Log:
o Removed JNDI from the searchResultEntry message
o Removed a useless method in RDN, with the associated test
Modified:
directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/PersistentSearchListener.java
directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntry.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntry.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImpl.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryTest.java
directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImplTest.java
Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/PersistentSearchListener.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/PersistentSearchListener.java?rev=690033&r1=690032&r2=690033&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/PersistentSearchListener.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/PersistentSearchListener.java Thu Aug 28 15:40:59 2008
@@ -22,7 +22,6 @@
import javax.naming.NamingException;
-import org.apache.directory.server.core.entry.ServerEntryUtils;
import org.apache.directory.server.core.event.DirectoryListener;
import org.apache.directory.server.core.interceptor.context.AddOperationContext;
import org.apache.directory.server.core.interceptor.context.ChangeOperationContext;
@@ -139,7 +138,7 @@
SearchResponseEntry respEntry = new SearchResponseEntryImpl( req.getMessageId() );
respEntry.setObjectName( opContext.getDn() );
- respEntry.setAttributes( ServerEntryUtils.toAttributesImpl( opContext.getEntry() ) );
+ respEntry.setEntry( opContext.getEntry() );
setECResponseControl( respEntry, opContext, ChangeType.ADD );
session.getIoSession().write( respEntry );
}
@@ -154,7 +153,7 @@
SearchResponseEntry respEntry = new SearchResponseEntryImpl( req.getMessageId() );
respEntry.setObjectName( opContext.getDn() );
- respEntry.setAttributes( ServerEntryUtils.toAttributesImpl( opContext.getEntry() ) );
+ respEntry.setEntry( opContext.getEntry() );
setECResponseControl( respEntry, opContext, ChangeType.DELETE );
session.getIoSession().write( respEntry );
}
@@ -169,7 +168,7 @@
SearchResponseEntry respEntry = new SearchResponseEntryImpl( req.getMessageId() );
respEntry.setObjectName( opContext.getDn() );
- respEntry.setAttributes( ServerEntryUtils.toAttributesImpl( opContext.getEntry() ) );
+ respEntry.setEntry( opContext.getEntry() );
setECResponseControl( respEntry, opContext, ChangeType.MODIFY );
session.getIoSession().write( respEntry );
}
@@ -184,7 +183,7 @@
SearchResponseEntry respEntry = new SearchResponseEntryImpl( req.getMessageId() );
respEntry.setObjectName( opContext.getDn() );
- respEntry.setAttributes( ServerEntryUtils.toAttributesImpl( opContext.getEntry() ) );
+ respEntry.setEntry( opContext.getEntry() );
setECResponseControl( respEntry, opContext, ChangeType.MODDN );
session.getIoSession().write( respEntry );
}
@@ -205,7 +204,7 @@
SearchResponseEntry respEntry = new SearchResponseEntryImpl( req.getMessageId() );
respEntry.setObjectName( opContext.getAlteredEntry().getDn() );
- respEntry.setAttributes( ServerEntryUtils.toAttributesImpl( opContext.getAlteredEntry() ) );
+ respEntry.setEntry( opContext.getAlteredEntry() );
setECResponseControl( respEntry, opContext, ChangeType.MODDN );
session.getIoSession().write( respEntry );
}
Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java?rev=690033&r1=690032&r2=690033&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java Thu Aug 28 15:40:59 2008
@@ -24,7 +24,6 @@
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.core.entry.ClonedServerEntry;
-import org.apache.directory.server.core.entry.ServerEntryUtils;
import org.apache.directory.server.core.entry.ServerStringValue;
import org.apache.directory.server.core.event.EventType;
import org.apache.directory.server.core.event.NotificationCriteria;
@@ -486,7 +485,7 @@
{
SearchResponseEntry respEntry;
respEntry = new SearchResponseEntryImpl( req.getMessageId() );
- respEntry.setAttributes( ServerEntryUtils.toAttributesImpl( entry ) );
+ respEntry.setEntry( entry );
respEntry.setObjectName( entry.getDn() );
return respEntry;
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java?rev=690033&r1=690032&r2=690033&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java Thu Aug 28 15:40:59 2008
@@ -1279,7 +1279,10 @@
// Store the name
if ( tlv.getLength() == 0 )
{
- searchResultEntry.addAttributeValues( type );
+ // The type can't be null
+ String msg = "The AttributeType can't be empty";
+ log.error( msg );
+ throw new DecoderException( msg );
}
else
{
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java?rev=690033&r1=690032&r2=690033&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java Thu Aug 28 15:40:59 2008
@@ -1140,7 +1140,7 @@
// Snickers : Attributes attributes -> Twix : ArrayList
// partialAttributeList
- searchResultEntry.setPartialAttributeList( snickersSearchResultResponse.getAttributes() );
+ searchResultEntry.setEntry( snickersSearchResultResponse.getEntry() );
// Set the operation into the LdapMessage
twixMessage.setProtocolOP( searchResultEntry );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntry.java?rev=690033&r1=690032&r2=690033&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntry.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntry.java Thu Aug 28 15:40:59 2008
@@ -25,10 +25,7 @@
import java.util.LinkedList;
import java.util.List;
-import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
import org.apache.directory.shared.asn1.ber.tlv.TLV;
import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
@@ -37,10 +34,12 @@
import org.apache.directory.shared.asn1.util.Asn1StringUtils;
import org.apache.directory.shared.ldap.codec.LdapConstants;
import org.apache.directory.shared.ldap.codec.LdapMessage;
-import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.util.AttributeUtils;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -70,17 +69,14 @@
// ~ Instance fields
// ----------------------------------------------------------------------------
- /** The DN of the returned entry */
- private LdapDN objectName;
-
/** A temporary storage for the byte[] representing the objectName */
private byte[] objectNameBytes;
- /** The attributes list. It contains javax.naming.directory.Attribute */
- private Attributes partialAttributeList = new AttributesImpl( true );
+ /** The entry */
+ private Entry entry = new DefaultClientEntry();
/** The current attribute being decoded */
- private Attribute currentAttributeValue;
+ private EntryAttribute currentAttributeValue;
/** The search result entry length */
private int searchResultEntryLength;
@@ -128,38 +124,38 @@
*/
public LdapDN getObjectName()
{
- return objectName;
+ return entry.getDn();
}
/**
- * Set the entry DN
+ * Set the entry DN.
*
* @param objectName The objectName to set.
*/
public void setObjectName( LdapDN objectName )
{
- this.objectName = objectName;
+ entry.setDn( objectName );
}
/**
- * Get the entry's attributes
+ * Get the entry.
*
- * @return Returns the partialAttributeList.
+ * @return Returns the entry
*/
- public Attributes getPartialAttributeList()
+ public Entry getEntry()
{
- return partialAttributeList;
+ return entry;
}
/**
- * Initialize the partial Attribute list.
+ * Initialize the entry.
*/
- public void setPartialAttributeList( Attributes partialAttributeList )
+ public void setEntry( Entry entry )
{
- this.partialAttributeList = partialAttributeList;
+ this.entry = entry;
}
@@ -170,9 +166,16 @@
*/
public void addAttributeValues( String type )
{
- currentAttributeValue = new AttributeImpl( type );
+ currentAttributeValue = new DefaultClientAttribute( type );
- partialAttributeList.put( currentAttributeValue );
+ try
+ {
+ entry.put( currentAttributeValue );
+ }
+ catch ( NamingException ne )
+ {
+ // Too bad... But there is nothing we can do.
+ }
}
@@ -183,7 +186,14 @@
*/
public void addAttributeValue( Object value )
{
- currentAttributeValue.add( value );
+ if ( value instanceof String )
+ {
+ currentAttributeValue.add( (String)value );
+ }
+ else
+ {
+ currentAttributeValue.add( (byte[])value );
+ }
}
@@ -229,7 +239,7 @@
*/
public int computeLength()
{
- objectNameBytes = StringTools.getBytesUtf8( objectName.getUpName() );
+ objectNameBytes = StringTools.getBytesUtf8( entry.getDn().getUpName() );
// The entry
searchResultEntryLength = 1 + TLV.getNbBytes( objectNameBytes.length ) + objectNameBytes.length;
@@ -237,70 +247,55 @@
// The attributes sequence
attributesLength = 0;
- if ( ( partialAttributeList != null ) && ( partialAttributeList.size() != 0 ) )
+ if ( ( entry != null ) && ( entry.size() != 0 ) )
{
- NamingEnumeration<? extends Attribute> attributes = partialAttributeList.getAll();
attributeLength = new LinkedList<Integer>();
valsLength = new LinkedList<Integer>();
// Compute the attributes length
- while ( attributes.hasMoreElements() )
+ for ( EntryAttribute attribute:entry )
{
- Attribute attribute = ( Attribute ) attributes.nextElement();
-
int localAttributeLength = 0;
int localValuesLength = 0;
// Get the type length
- int idLength = attribute.getID().getBytes().length;
+ int idLength = attribute.getId().getBytes().length;
localAttributeLength = 1 + TLV.getNbBytes( idLength ) + idLength;
if ( attribute.size() != 0 )
{
// The values
- try
+ if ( attribute.size() > 0 )
{
- NamingEnumeration<?> values = attribute.getAll();
+ localValuesLength = 0;
- if ( values.hasMoreElements() )
+ for ( org.apache.directory.shared.ldap.entry.Value<?> value:attribute )
{
- localValuesLength = 0;
-
- while ( values.hasMoreElements() )
+ if ( value instanceof ClientStringValue )
{
- Object value = values.next();
-
- if ( value instanceof String )
- {
- String stringValue = ( String ) value;
-
- int stringLength = StringTools.getBytesUtf8( stringValue ).length;
- localValuesLength += 1 + TLV.getNbBytes( stringLength ) + stringLength;
- }
- else
- {
- byte[] binaryValue = ( byte[] ) value;
- localValuesLength += 1 + TLV.getNbBytes( binaryValue.length )
- + binaryValue.length;
- }
+ String stringValue = ( String ) value.get();
+ int stringLength = StringTools.getBytesUtf8( stringValue ).length;
+ localValuesLength += 1 + TLV.getNbBytes( stringLength ) + stringLength;
+ }
+ else
+ {
+ byte[] binaryValue = ( byte[] ) value.get();
+ localValuesLength += 1 + TLV.getNbBytes( binaryValue.length )
+ + binaryValue.length;
}
- localAttributeLength += 1 + TLV.getNbBytes( localValuesLength ) + localValuesLength;
- }
- else
- {
- // We have to deal with the special wase where
- // we don't have a value.
- // It will be encoded as an empty OCTETSTRING,
- // so it will be two byte slong (0x04 0x00)
- localAttributeLength += 1 + 1;
}
+ localAttributeLength += 1 + TLV.getNbBytes( localValuesLength ) + localValuesLength;
}
- catch ( NamingException ne )
+ else
{
- return 0;
+ // We have to deal with the special wase where
+ // we don't have a value.
+ // It will be encoded as an empty OCTETSTRING,
+ // so it will be two byte slong (0x04 0x00)
+ localAttributeLength += 1 + 1;
}
}
else
@@ -371,23 +366,20 @@
buffer.put( TLV.getBytes( attributesLength ) );
// The partial attribute list
- if ( ( partialAttributeList != null ) && ( partialAttributeList.size() != 0 ) )
+ if ( ( entry != null ) && ( entry.size() != 0 ) )
{
- NamingEnumeration<? extends Attribute> attributes = partialAttributeList.getAll();
int attributeNumber = 0;
// Compute the attributes length
- while ( attributes.hasMoreElements() )
+ for ( EntryAttribute attribute:entry )
{
- Attribute attribute = ( Attribute ) attributes.nextElement();
-
// The partial attribute list sequence
buffer.put( UniversalTag.SEQUENCE_TAG );
int localAttributeLength = attributeLength.get( attributeNumber );
buffer.put( TLV.getBytes( localAttributeLength ) );
// The attribute type
- Value.encode( buffer, Asn1StringUtils.asciiStringToByte( attribute.getID() ) );
+ Value.encode( buffer, Asn1StringUtils.asciiStringToByte( attribute.getUpId() ) );
// The values
buffer.put( UniversalTag.SET_TAG );
@@ -396,31 +388,20 @@
if ( attribute.size() != 0 )
{
- try
+ if ( attribute.size() > 0 )
{
- NamingEnumeration<?> values = attribute.getAll();
-
- if ( values.hasMoreElements() )
+ for ( org.apache.directory.shared.ldap.entry.Value<?> value:attribute )
{
- while ( values.hasMoreElements() )
+ if ( value instanceof ClientStringValue )
{
- Object value = values.next();
-
- if ( value instanceof String )
- {
- Value.encode( buffer, ( String ) value );
- }
- else
- {
- Value.encode( buffer, ( byte[] ) value );
- }
+ Value.encode( buffer, ( String ) value.get() );
+ }
+ else
+ {
+ Value.encode( buffer, ( byte[] ) value.get() );
}
}
}
- catch ( NamingException ne )
- {
- throw new EncoderException( "Cannot enumerate the values" );
- }
}
// Go to the next attribute number;
@@ -445,19 +426,18 @@
public String toString()
{
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
sb.append( " Search Result Entry\n" );
- sb.append( " Object Name : '" ).append( objectName ).append( "'\n" );
- sb.append( " Attributes\n" );
+ sb.append( " entry\n" );
- if ( ( partialAttributeList == null ) || ( partialAttributeList.size() == 0 ) )
+ if ( ( entry == null ) || ( entry.size() == 0 ) )
{
- sb.append( " No attributes\n" );
+ sb.append( " No entry\n" );
}
else
{
- sb.append( AttributeUtils.toString( " ", partialAttributeList ) );
+ sb.append( entry );
}
return sb.toString();
@@ -469,6 +449,6 @@
*/
public String getCurrentAttributeValueType()
{
- return currentAttributeValue.getID();
+ return currentAttributeValue.getId();
}
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntry.java?rev=690033&r1=690032&r2=690033&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntry.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntry.java Thu Aug 28 15:40:59 2008
@@ -21,8 +21,7 @@
package org.apache.directory.shared.ldap.message;
-import javax.naming.directory.Attributes;
-
+import org.apache.directory.shared.ldap.entry.Entry;
import org.apache.directory.shared.ldap.name.LdapDN;
@@ -56,18 +55,17 @@
/**
- * Gets the set of attributes and all their values in a MultiMap.
+ * Gets the entry.
*
- * @return the set of attributes and all their values
+ * @return the entry
*/
- Attributes getAttributes();
+ Entry getEntry();
/**
- * Sets the set of attributes and all their values in a MultiMap.
+ * Sets an entry
*
- * @param attributes
- * the set of attributes and all their values
+ * @param entry the entry
*/
- void setAttributes( Attributes attributes );
+ void setEntry( Entry entry );
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImpl.java?rev=690033&r1=690032&r2=690033&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImpl.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImpl.java Thu Aug 28 15:40:59 2008
@@ -20,10 +20,8 @@
package org.apache.directory.shared.ldap.message;
-import javax.naming.directory.Attributes;
-
+import org.apache.directory.shared.ldap.entry.Entry;
import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.util.AttributeUtils;
/**
@@ -36,11 +34,8 @@
{
static final long serialVersionUID = -8357316233060886637L;
- /** Distinguished name of the search result entry returned */
- private LdapDN objectName;
-
- /** Partial set of attributes returned in response to search */
- private Attributes attributes;
+ /** Entry returned in response to search */
+ private Entry entry;
// ------------------------------------------------------------------------
@@ -48,13 +43,12 @@
// ------------------------------------------------------------------------
/**
- * Creates a Lockable SearchResponseEntry as a reply to an SearchRequest to
+ * Creates a SearchResponseEntry as a reply to an SearchRequest to
* indicate the end of a search operation.
*
- * @param id
- * the session unique message id
+ * @param id the session unique message id
*/
- public SearchResponseEntryImpl(final int id)
+ public SearchResponseEntryImpl( final int id )
{
super( id, TYPE );
}
@@ -65,25 +59,24 @@
// ------------------------------------------------------------------------
/**
- * Gets the set of attributes and all their values in a Attributes.
+ * Gets the entry
*
- * @return the set of attributes and all their values
+ * @return the entry
*/
- public Attributes getAttributes()
+ public Entry getEntry()
{
- return attributes;
+ return entry;
}
/**
- * Sets the set of attributes and all their values in a Attributes.
+ * Sets the entry.
*
- * @param attributes
- * the set of attributes and all their values
+ * @param entry the entry
*/
- public void setAttributes( Attributes attributes )
+ public void setEntry( Entry entry )
{
- this.attributes = attributes;
+ this.entry = entry;
}
@@ -94,7 +87,7 @@
*/
public LdapDN getObjectName()
{
- return objectName;
+ return ( entry == null ? null : entry.getDn() );
}
@@ -106,7 +99,10 @@
*/
public void setObjectName( LdapDN objectName )
{
- this.objectName = objectName;
+ if ( entry != null )
+ {
+ entry.setDn( objectName );
+ }
}
@@ -130,29 +126,14 @@
return false;
}
- SearchResponseEntry resp = ( SearchResponseEntry ) obj;
-
- if ( !objectName.equals( resp.getObjectName() ) )
- {
- return false;
- }
-
- if ( attributes == null && resp.getAttributes() != null )
- {
- return false;
- }
-
- if ( attributes != null && resp.getAttributes() == null )
+ if ( !( obj instanceof SearchResponseEntry ) )
{
return false;
}
+
+ SearchResponseEntry resp = ( SearchResponseEntry ) obj;
- if ( attributes != null && resp.getAttributes() != null )
- {
- return attributes.equals( resp.getAttributes() );
- }
-
- return true;
+ return entry.equals( resp.getEntry() );
}
@@ -161,19 +142,17 @@
*/
public String toString()
{
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
sb.append( " Search Result Entry\n" );
- sb.append( " Object Name : '" ).append( objectName.toString() ).append( "'\n" );
- sb.append( " Attributes\n" );
- if ( attributes != null )
+ if ( entry != null )
{
- sb.append( AttributeUtils.toString( attributes ) );
+ sb.append( entry );
}
else
{
- sb.append( " No attributes\n" );
+ sb.append( " No entry\n" );
}
return sb.toString();
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java?rev=690033&r1=690032&r2=690033&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java Thu Aug 28 15:40:59 2008
@@ -31,12 +31,8 @@
import java.util.TreeSet;
import javax.naming.InvalidNameException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
import org.apache.commons.collections.map.MultiValueMap;
-import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.message.AttributesImpl;
import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -995,49 +991,6 @@
/**
- * Transform the Rdn into an javax.naming.directory.Attributes
- *
- * @return An attributes structure containing all the ATAVs
- */
- public Attributes toAttributes()
- {
- Attributes attributes = new AttributesImpl( true );
- Attribute attribute = null;
-
- switch ( nbAtavs )
- {
- case 0 :
- break;
-
- case 1 :
- attribute = new AttributeImpl( atavType, true );
- attribute.add( atav.getNormValue() );
- attributes.put( attribute );
- break;
-
- default :
- for ( String type:atavTypes.keySet() )
- {
- List<AttributeTypeAndValue> values = ( List<AttributeTypeAndValue> ) atavTypes.get( type );
-
- attribute = new AttributeImpl( type );
-
- for ( AttributeTypeAndValue value:values )
- {
- attribute.add( value.getNormValue() );
- }
-
- attributes.put( attribute );
- }
-
- break;
- }
-
- return attributes;
- }
-
-
- /**
* Unescape the given string according to RFC 2253 If in <string> form, a
* LDAP string representation asserted value can be obtained by replacing
* (left-to-right, non-recursively) each <pair> appearing in the <string> as
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryTest.java?rev=690033&r1=690032&r2=690033&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryTest.java Thu Aug 28 15:40:59 2008
@@ -21,14 +21,9 @@
import java.nio.ByteBuffer;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
import org.apache.directory.shared.asn1.ber.Asn1Decoder;
import org.apache.directory.shared.asn1.ber.IAsn1Container;
@@ -39,6 +34,8 @@
import org.apache.directory.shared.ldap.codec.LdapMessage;
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
import org.apache.directory.shared.ldap.codec.search.SearchResultEntry;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.util.StringTools;
import junit.framework.TestCase;
@@ -105,31 +102,18 @@
assertEquals( 1, message.getMessageId() );
assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
- Attributes partialAttributesList = searchResultEntry.getPartialAttributeList();
+ Entry entry = searchResultEntry.getEntry();
- assertEquals( 1, partialAttributesList.size() );
+ assertEquals( 1, entry.size() );
- for ( int i = 0; i < partialAttributesList.size(); i++ )
+ for ( int i = 0; i < entry.size(); i++ )
{
- Attribute attributeValue = partialAttributesList.get( "objectclass" );
+ EntryAttribute attribute = entry.get( "objectclass" );
- assertEquals( "objectClass".toLowerCase(), attributeValue.getID().toLowerCase() );
+ assertEquals( "objectClass".toLowerCase(), attribute.getId().toLowerCase() );
- NamingEnumeration<?> values = attributeValue.getAll();
-
- Set<String> expectedValues = new HashSet<String>();
-
- expectedValues.add( "top" );
- expectedValues.add( "organizationalUnit" );
-
- while ( values.hasMore() )
- {
- Object value = values.next();
-
- assertTrue( expectedValues.contains( value.toString() ) );
-
- expectedValues.remove( value.toString() );
- }
+ assertTrue( attribute.contains( "top" ) );
+ assertTrue( attribute.contains( "organizationalUnit" ) );
}
// Check the length
@@ -212,34 +196,21 @@
assertEquals( 1, message.getMessageId() );
assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
- Attributes partialAttributesList = searchResultEntry.getPartialAttributeList();
+ Entry entry = searchResultEntry.getEntry();
- assertEquals( 2, partialAttributesList.size() );
+ assertEquals( 2, entry.size() );
String[] expectedAttributes = new String[]
{ "objectClass", "objectClass2" };
for ( int i = 0; i < expectedAttributes.length; i++ )
{
- Attribute attributeValue = partialAttributesList.get( expectedAttributes[i] );
-
- assertEquals( expectedAttributes[i].toLowerCase(), attributeValue.getID().toLowerCase() );
+ EntryAttribute attribute = entry.get( expectedAttributes[i] );
- NamingEnumeration<?> values = attributeValue.getAll();
+ assertEquals( expectedAttributes[i].toLowerCase(), attribute.getId().toLowerCase() );
- Set<String> expectedValues = new HashSet<String>();
-
- expectedValues.add( "top" );
- expectedValues.add( "organizationalUnit" );
-
- while ( values.hasMore() )
- {
- Object value = values.next();
-
- assertTrue( expectedValues.contains( value.toString() ) );
-
- expectedValues.remove( value.toString() );
- }
+ assertTrue( attribute.contains( "top" ) );
+ assertTrue( attribute.contains( "organizationalUnit" ) );
}
// Check the length
@@ -250,7 +221,7 @@
{
message.encode( null );
- // We cant compare the encodings, the order of the attributes has
+ // We can't compare the encodings, the order of the attributes has
// changed
}
catch ( EncoderException ee )
@@ -324,33 +295,20 @@
assertEquals( 2, message.getMessageId() );
assertEquals( "uid=admin,ou=system", searchResultEntry.getObjectName().toString() );
- Attributes partialAttributesList = searchResultEntry.getPartialAttributeList();
+ Entry entry = searchResultEntry.getEntry();
- assertEquals( 1, partialAttributesList.size() );
+ assertEquals( 1, entry.size() );
- for ( int i = 0; i < partialAttributesList.size(); i++ )
+ for ( int i = 0; i < entry.size(); i++ )
{
- Attribute attributeValue = partialAttributesList.get( "objectclass" );
-
- assertEquals( "objectClass".toLowerCase(), attributeValue.getID().toLowerCase() );
-
- NamingEnumeration<?> values = attributeValue.getAll();
+ EntryAttribute attribute = entry.get( "objectclass" );
- Set<String> expectedValues = new HashSet<String>();
+ assertEquals( "objectClass".toLowerCase(), attribute.getId().toLowerCase() );
- expectedValues.add( "top" );
- expectedValues.add( "person" );
- expectedValues.add( "organizationalPerson" );
- expectedValues.add( "inetOrgPerson" );
-
- while ( values.hasMore() )
- {
- Object value = values.next();
-
- assertTrue( expectedValues.contains( value.toString() ) );
-
- expectedValues.remove( value.toString() );
- }
+ assertTrue( attribute.contains( "top" ) );
+ assertTrue( attribute.contains( "person" ) );
+ assertTrue( attribute.contains( "organizationalPerson" ) );
+ assertTrue( attribute.contains( "inetOrgPerson" ) );
}
// Check the length
@@ -544,9 +502,9 @@
assertEquals( 1, message.getMessageId() );
assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
- Attributes partialAttributesList = searchResultEntry.getPartialAttributeList();
+ Entry entry = searchResultEntry.getEntry();
- assertEquals( 0, partialAttributesList.size() );
+ assertEquals( 0, entry.size() );
// Check the length
assertEquals( 0x26, message.computeLength() );
@@ -797,19 +755,16 @@
assertEquals( 1, message.getMessageId() );
assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
- Attributes partialAttributesList = searchResultEntry.getPartialAttributeList();
+ Entry entry = searchResultEntry.getEntry();
- assertEquals( 1, partialAttributesList.size() );
+ assertEquals( 1, entry.size() );
- for ( int i = 0; i < partialAttributesList.size(); i++ )
+ for ( int i = 0; i < entry.size(); i++ )
{
- Attribute attributeValue = partialAttributesList.get( "objectclass" );
+ EntryAttribute attribute = entry.get( "objectclass" );
- assertEquals( "objectClass".toLowerCase(), attributeValue.getID().toLowerCase() );
-
- NamingEnumeration<?> values = attributeValue.getAll();
-
- assertFalse( values.hasMore() );
+ assertEquals( "objectClass".toLowerCase(), attribute.getId().toLowerCase() );
+ assertEquals( 0, attribute.size() );
}
// Check the length
@@ -882,19 +837,17 @@
assertEquals( 1, message.getMessageId() );
assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
- Attributes partialAttributesList = searchResultEntry.getPartialAttributeList();
+ Entry entry = searchResultEntry.getEntry();
+
+ assertEquals( 2, entry.size() );
- assertEquals( 2, partialAttributesList.size() );
+ EntryAttribute attribute = entry.get( "objectclass" );
+ assertEquals( "objectClass".toLowerCase(), attribute.getId().toLowerCase() );
+ assertEquals( 0, attribute.size() );
- Attribute attributeValue = partialAttributesList.get( "objectclass" );
- assertEquals( "objectClass".toLowerCase(), attributeValue.getID().toLowerCase() );
- NamingEnumeration<?> values = attributeValue.getAll();
- assertFalse( values.hasMore() );
-
- attributeValue = partialAttributesList.get( "objectclazz" );
- assertEquals( "objectClazz".toLowerCase(), attributeValue.getID().toLowerCase() );
- values = attributeValue.getAll();
- assertFalse( values.hasMore() );
+ attribute = entry.get( "objectclazz" );
+ assertEquals( "objectClazz".toLowerCase(), attribute.getId().toLowerCase() );
+ assertEquals( 0, attribute.size() );
// Check the length
assertEquals( 0x48, message.computeLength() );
@@ -967,19 +920,17 @@
assertEquals( 1, message.getMessageId() );
assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
- Attributes partialAttributesList = searchResultEntry.getPartialAttributeList();
+ Entry entry = searchResultEntry.getEntry();
- assertEquals( 1, partialAttributesList.size() );
+ assertEquals( 1, entry.size() );
- for ( int i = 0; i < partialAttributesList.size(); i++ )
+ for ( int i = 0; i < entry.size(); i++ )
{
- Attribute attributeValue = partialAttributesList.get( "objectclass" );
+ EntryAttribute attribute = entry.get( "objectclass" );
- assertEquals( "objectClass".toLowerCase(), attributeValue.getID().toLowerCase() );
+ assertEquals( "objectClass".toLowerCase(), attribute.getId().toLowerCase() );
- NamingEnumeration<?> values = attributeValue.getAll();
-
- assertFalse( values.hasMore() );
+ assertEquals( 0, attribute.size() );
}
// Check the Control
@@ -1061,24 +1012,17 @@
assertEquals( 1, message.getMessageId() );
assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
- Attributes partialAttributesList = searchResultEntry.getPartialAttributeList();
+ Entry entry = searchResultEntry.getEntry();
- assertEquals( 1, partialAttributesList.size() );
+ assertEquals( 1, entry.size() );
- for ( int i = 0; i < partialAttributesList.size(); i++ )
+ for ( int i = 0; i < entry.size(); i++ )
{
- Attribute attributeValue = partialAttributesList.get( "objectclass" );
-
- assertEquals( "objectClass".toLowerCase(), attributeValue.getID().toLowerCase() );
+ EntryAttribute attribute = entry.get( "objectclass" );
- NamingEnumeration<?> values = attributeValue.getAll();
-
- while ( values.hasMore() )
- {
- Object value = values.next();
+ assertEquals( "objectClass".toLowerCase(), attribute.getId().toLowerCase() );
- assertEquals( "", value.toString() );
- }
+ assertTrue( attribute.contains( "" ) );
}
// Check the length
@@ -1154,24 +1098,17 @@
assertEquals( 1, message.getMessageId() );
assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString() );
- Attributes partialAttributesList = searchResultEntry.getPartialAttributeList();
+ Entry entry = searchResultEntry.getEntry();
- assertEquals( 1, partialAttributesList.size() );
+ assertEquals( 1, entry.size() );
- for ( int i = 0; i < partialAttributesList.size(); i++ )
+ for ( int i = 0; i < entry.size(); i++ )
{
- Attribute attributeValue = partialAttributesList.get( "objectclass" );
+ EntryAttribute attribute = entry.get( "objectclass" );
- assertEquals( "objectClass".toLowerCase(), attributeValue.getID().toLowerCase() );
-
- NamingEnumeration<?> values = attributeValue.getAll();
-
- while ( values.hasMore() )
- {
- Object value = values.next();
+ assertEquals( "objectClass".toLowerCase(), attribute.getId().toLowerCase() );
- assertEquals( "", value.toString() );
- }
+ assertTrue( attribute.contains( "" ) );
}
// Check the Control
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImplTest.java?rev=690033&r1=690032&r2=690033&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImplTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImplTest.java Thu Aug 28 15:40:59 2008
@@ -26,11 +26,13 @@
import java.util.Map;
import javax.naming.InvalidNameException;
-import javax.naming.directory.Attributes;
+import javax.naming.NamingException;
import javax.naming.ldap.Control;
-import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
import org.apache.directory.shared.ldap.message.MessageException;
import org.apache.directory.shared.ldap.message.MessageTypeEnum;
import org.apache.directory.shared.ldap.message.SearchResponseEntry;
@@ -49,15 +51,14 @@
private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
/**
- * Creates and populates a AttributeImpl with a specific id.
+ * Creates and populates an EntryAttribute with a specific id.
*
- * @param id
- * the id for the attribute
- * @return the AttributeImpl assembled for testing
+ * @param id the id for the attribute
+ * @return the EntryAttribute assembled for testing
*/
- private AttributeImpl getAttribute( String id )
+ private EntryAttribute getEntry( String id )
{
- AttributeImpl attr = new AttributeImpl( id );
+ EntryAttribute attr = new DefaultClientAttribute( id );
attr.add( "value0" );
attr.add( "value1" );
attr.add( "value2" );
@@ -66,16 +67,16 @@
/**
- * Creates and populates a LockableAttributes object
+ * Creates and populates an Entry object
*
- * @return
+ * @return The populated Entry object
*/
- AttributesImpl getAttributes()
+ Entry getEntry() throws NamingException
{
- AttributesImpl attrs = new AttributesImpl();
- attrs.put( getAttribute( "attr0" ) );
- attrs.put( getAttribute( "attr1" ) );
- attrs.put( getAttribute( "attr2" ) );
+ Entry attrs = new DefaultClientEntry();
+ attrs.put( getEntry( "attr0" ) );
+ attrs.put( getEntry( "attr1" ) );
+ attrs.put( getEntry( "attr2" ) );
return attrs;
}
@@ -93,14 +94,14 @@
/**
* Tests for equality when an exact copy is compared.
*/
- public void testEqualsExactCopy() throws InvalidNameException
+ public void testEqualsExactCopy() throws InvalidNameException, NamingException
{
SearchResponseEntryImpl resp0 = new SearchResponseEntryImpl( 5 );
- resp0.setAttributes( getAttributes() );
+ resp0.setEntry( getEntry() );
resp0.setObjectName( new LdapDN( "dc=example,dc=com" ) );
SearchResponseEntryImpl resp1 = new SearchResponseEntryImpl( 5 );
- resp1.setAttributes( getAttributes() );
+ resp1.setEntry( getEntry() );
resp1.setObjectName( new LdapDN( "dc=example,dc=com" ) );
assertTrue( "exact copies should be equal", resp0.equals( resp1 ) );
@@ -109,121 +110,16 @@
/**
- * Tests for equality when a different implementation is used.
- */
- public void testEqualsDiffImpl()
- {
- SearchResponseEntry resp0 = new SearchResponseEntry()
- {
- public LdapDN getObjectName()
- {
- try
- {
- return new LdapDN( "dc=example,dc=com" );
- }
- catch ( InvalidNameException ine )
- {
- // Do nothing
- return null;
- }
- }
-
-
- public void setObjectName( LdapDN dn )
- {
- }
-
-
- public Attributes getAttributes()
- {
- return SearchResponseEntryImplTest.this.getAttributes();
- }
-
-
- public void setAttributes( Attributes attributes )
- {
- }
-
-
- public MessageTypeEnum getType()
- {
- return MessageTypeEnum.SEARCH_RES_ENTRY;
- }
-
-
- public Map<String, Control> getControls()
- {
- return EMPTY_CONTROL_MAP;
- }
-
-
- public void add( Control control ) throws MessageException
- {
- }
-
-
- public void remove( Control control ) throws MessageException
- {
- }
-
-
- public int getMessageId()
- {
- return 5;
- }
-
-
- public Object get( Object key )
- {
- return null;
- }
-
-
- public Object put( Object key, Object value )
- {
- return null;
- }
-
-
- public void addAll( Control[] controls ) throws MessageException
- {
- }
-
-
- public boolean hasControl( String oid )
- {
- return false;
- }
- };
-
- SearchResponseEntryImpl resp1 = new SearchResponseEntryImpl( 5 );
- resp1.setAttributes( getAttributes() );
-
- try
- {
- resp1.setObjectName( new LdapDN( "dc=example,dc=com" ) );
- }
- catch ( Exception e )
- {
- // Do nothing
- }
-
- assertFalse( "using Object.equal() should NOT be equal", resp0.equals( resp1 ) );
- assertTrue( "same but different implementations should be equal", resp1.equals( resp0 ) );
- }
-
-
- /**
* Tests for inequality when the objectName dn is not the same.
*/
- public void testNotEqualDiffObjectName() throws InvalidNameException
+ public void testNotEqualDiffObjectName() throws InvalidNameException, NamingException
{
SearchResponseEntryImpl resp0 = new SearchResponseEntryImpl( 5 );
- resp0.setAttributes( getAttributes() );
+ resp0.setEntry( getEntry() );
resp0.setObjectName( new LdapDN( "dc=apache,dc=org" ) );
SearchResponseEntryImpl resp1 = new SearchResponseEntryImpl( 5 );
- resp1.setAttributes( getAttributes() );
+ resp1.setEntry( getEntry() );
resp1.setObjectName( new LdapDN( "dc=example,dc=com" ) );
assertFalse( "different object names should not be equal", resp1.equals( resp0 ) );
@@ -234,15 +130,15 @@
/**
* Tests for inequality when the attributes are not the same.
*/
- public void testNotEqualDiffAttributes() throws InvalidNameException
+ public void testNotEqualDiffAttributes() throws InvalidNameException, NamingException
{
SearchResponseEntryImpl resp0 = new SearchResponseEntryImpl( 5 );
- resp0.setAttributes( getAttributes() );
- resp0.getAttributes().put( "abc", "123" );
+ resp0.setEntry( getEntry() );
+ resp0.getEntry().put( "abc", "123" );
resp0.setObjectName( new LdapDN( "dc=apache,dc=org" ) );
SearchResponseEntryImpl resp1 = new SearchResponseEntryImpl( 5 );
- resp1.setAttributes( getAttributes() );
+ resp1.setEntry( getEntry() );
resp1.setObjectName( new LdapDN( "dc=apache,dc=org" ) );
assertFalse( "different attributes should not be equal", resp1.equals( resp0 ) );