|
|
Copied:
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java
(from r493207,
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/LockableAttributeImpl.java)
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java?view=diff&rev=493916&p1=directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/LockableAttributeImpl.java&r1=493207&p2=directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/LockableAttributeImpl.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java
Sun Jan 7 18:44:33 2007
@@ -21,8 +21,11 @@
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
@@ -30,6 +33,7 @@
import javax.naming.directory.Attribute;
import javax.naming.directory.DirContext;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,9 +45,9 @@
* @author <a href="mailto:dev@xxxxxxxxxxxxxxxxxxxx"> Apache Directory
Project</a>
* @version $Rev$
*/
-public class LockableAttributeImpl implements Attribute
+public class AttributeImpl implements Attribute
{
- private static final Logger log = LoggerFactory.getLogger(
LockableAttributeImpl.class );
+ private static final Logger log = LoggerFactory.getLogger(
AttributeImpl.class );
private static final long serialVersionUID = -5158233254341746514L;
@@ -53,86 +57,65 @@
/** In case we have only one value, just use this container */
private Object value;
- /** the list of attribute values */
+ /** the list of attribute values, if unordered */
private List list;
/** The number of values stored */
private int size = 0;
-
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
/**
- * Creates a permanently LockableAttribute on id whose locking behavoir is
- * dicatated by parent.
+ * Creates a permanently Attribute on id whose locking behavior is
+ * dictated by parent.
*
* @param id
* the id or name of this attribute.
*/
- public LockableAttributeImpl(final String id)
+ public AttributeImpl( String id )
{
upId = id;
value = null;
- list = null; //new ArrayList();
+ list = null;
size = 0;
}
/**
- * Creates a permanently LockableAttribute on id with a single value.
+ * Creates a permanently Attribute on id with a single value.
*
* @param id
* the id or name of this attribute.
* @param value
* a value for the attribute
*/
- public LockableAttributeImpl(final String id, final Object value)
+ public AttributeImpl( String id, Object value )
{
upId = id;
- list = null; // new ArrayList();
- this.value = value; //list.add( value );
+ list = null;
+ this.value = AttributeUtils.cloneValue( value );
size = 1;
}
/**
- * Creates a permanently LockableAttribute on id with a single value.
+ * Creates a permanently Attribute on id with a single value.
*
* @param id
* the id or name of this attribute.
* @param value
* a value for the attribute
*/
- public LockableAttributeImpl(final String id, final byte[] value)
+ public AttributeImpl( String id, byte[] value )
{
upId = id;
- list = null; //new ArrayList();
- this.value = value;
- //list.add( value );
+ list = null;
+ this.value = AttributeUtils.cloneValue( value );
size = 1;
}
-
- /**
- * Creates a permanently LockableAttribute on id whose locking behavoir is
- * dicatated by parent. Used for the clone method.
- *
- * @param id
- * the id or name of this attribute
- * @param list
- * the list of values to start with
- */
- private LockableAttributeImpl(final String id, final List list)
- {
- upId = id;
- this.list = list;
- value = null;
- size = (list != null ? list.size() : 0);
- }
-
-
// ------------------------------------------------------------------------
// javax.naming.directory.Attribute Interface Method Implementations
// ------------------------------------------------------------------------
@@ -148,30 +131,30 @@
{
return new IteratorNamingEnumeration( new Iterator()
{
- private boolean done = (size != 0);
+ private boolean more = (size != 0);
public boolean hasNext()
{
- return done;
+ return more;
}
public Object next()
{
- done = false;
+ more = false;
return value;
}
public void remove()
{
value = null;
- done = false;
+ more = true;
size = 0;
}
});
}
else
{
- return new IteratorNamingEnumeration( list.iterator() );
+ return new IteratorNamingEnumeration( list.iterator() );
}
}
@@ -183,18 +166,14 @@
*/
public Object get()
{
- if ( list == null )
- {
+ if ( size < 2 )
+ {
return value;
}
- else if ( list.isEmpty() )
+ else
{
- return null;
+ return list.get( 0 );
}
- else
- {
- return list.get( 0 );
- }
}
@@ -235,10 +214,20 @@
return false;
case 1 :
- return value == null ? attrVal == null : value.equals(
attrVal );
+ return AttributeUtils.equals( value, attrVal );
default :
- return list.contains( attrVal );
+ Iterator values = list.iterator();
+
+ while ( values.hasNext() )
+ {
+ if ( AttributeUtils.equals( values.next(), attrVal ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
}
}
@@ -255,7 +244,16 @@
public boolean add( Object attrVal )
{
boolean exists = false;
-
+
+ if ( contains( attrVal ) )
+ {
+ // Do not duplicate values
+ return true;
+ }
+
+ // First copy the value
+ attrVal = AttributeUtils.cloneValue( attrVal );
+
switch ( size )
{
case 0 :
@@ -266,12 +264,20 @@
case 1 :
exists = value.equals( attrVal );
- list = new ArrayList();
- list.add( value );
- list.add( attrVal );
- size++;
- value = null;
- return exists;
+ if ( exists )
+ {
+ // Don't add two times the same value
+ return true;
+ }
+ else
+ {
+ list = new ArrayList();
+ list.add( value );
+ list.add( attrVal );
+ size++;
+ value = null;
+ return true;
+ }
default :
exists = list.contains( attrVal );
@@ -303,7 +309,7 @@
size--;
return true;
- case 2 :
+ case 2 :
list.remove( attrVal );
value = list.get(0);
size = 1;
@@ -371,17 +377,31 @@
*/
public Object clone()
{
- switch ( size )
- {
- case 0 :
- return new LockableAttributeImpl( upId );
-
- case 1 :
- return new LockableAttributeImpl( upId, value );
-
- default :
- return new LockableAttributeImpl( upId,
(List)((ArrayList)list).clone() );
- }
+ try
+ {
+ AttributeImpl clone = (AttributeImpl)super.clone();
+
+ if ( size < 2 )
+ {
+ clone.value = AttributeUtils.cloneValue( value );
+ }
+ else
+ {
+ clone.list = new ArrayList( size );
+
+ for ( int i = 0; i < size; i++ )
+ {
+ Object newValue = AttributeUtils.cloneValue( list.get( i )
);
+ clone.list.add( newValue );
+ }
+ }
+
+ return clone;
+ }
+ catch ( CloneNotSupportedException cnse )
+ {
+ return null;
+ }
}
@@ -406,6 +426,11 @@
*/
public Object get( int index )
{
+ if ( (index < 0 ) || ( index > size + 1 ) )
+ {
+ return null;
+ }
+
switch ( size )
{
case 0 :
@@ -415,7 +440,7 @@
return value;
default :
- return list.get( index );
+ return list.get( index );
}
}
@@ -430,6 +455,11 @@
*/
public Object remove( int index )
{
+ if ( (index < 0 ) || ( index > size + 1 ) )
+ {
+ return null;
+ }
+
switch ( size )
{
case 0 :
@@ -441,9 +471,18 @@
size = 0;
return result;
+ case 2 :
+ Object removed = list.remove( index );
+ value = list.get(0);
+ size = 1;
+ list = null;
+ return removed;
+
+
default :
size--;
- return list.remove( index );
+
+ return list.remove( index );
}
}
@@ -459,6 +498,9 @@
*/
public void add( int index, Object attrVal )
{
+ // First copy the value
+ attrVal = AttributeUtils.cloneValue( attrVal );
+
switch ( size )
{
case 0 :
@@ -503,6 +545,9 @@
*/
public Object set( int index, Object attrVal )
{
+ // First copy the value
+ attrVal = AttributeUtils.cloneValue( attrVal );
+
switch ( size )
{
case 0 :
@@ -556,7 +601,7 @@
return true;
}
- if ( !( obj instanceof Attribute ) )
+ if ( ( obj == null ) || !( obj instanceof AttributeImpl ) )
{
return false;
}
@@ -573,43 +618,130 @@
return false;
}
- switch ( size )
+ if ( size == 0 )
+ {
+ return true;
+ }
+ else if ( size == 1 )
{
- case 0 :
- return true;
-
- case 1 :
- try
+ try
+ {
+ return ( value.equals( attr.get( 0 ) ) );
+ }
+ catch ( NamingException ne )
+ {
+ log.warn( "Failed to get an attribute from the specifid
attribute: " + attr, ne );
+ return false;
+ }
+ }
+ else
+ {
+ // We have to create one hashSet to store all the values
+ // of the current attribute, and we will remove from this
+ // hashSet all the values from the second attribute which
+ // are present. At the end, the hashSet should be empty,
+ // and we should not have any value remaining in the second
+ // attribute. If not, that means the attributes are not
+ // equals.
+ //
+ // We have to do that because attribute's values are
+ // not ordered.
+ Map hash = new HashMap();
+
+ Iterator values = list.iterator();
+
+ while ( values.hasNext() )
+ {
+ Object v = values.next();
+ int h = 0;
+
+ if ( v instanceof String )
+ {
+ h = v.hashCode();
+ }
+ else if ( v instanceof byte[] )
{
- return value.equals( attr.get( 0 ) );
+ byte[] bv = (byte[])v;
+ h = Arrays.hashCode( bv );
}
- catch ( NamingException e )
+ else
{
- log.warn( "Failed to get an attribute from the specifid
attribute: " + attr, e );
return false;
}
-
- default :
- for ( int i = 0; i < size; i++ )
+
+ hash.put( Integer.valueOf( h ), v );
+ }
+
+ try
+ {
+ NamingEnumeration attrValues = attr.getAll();
+
+ while ( attrValues.hasMoreElements() )
{
- try
+ Object val = attrValues.next();
+
+ if ( val instanceof String )
+ {
+ Integer h = Integer.valueOf( val.hashCode() );
+
+ if ( !hash.containsKey( h ) )
+ {
+ return false;
+ }
+ else
+ {
+ Object val2 = hash.remove( h );
+
+ if ( !val.equals( val2 ) )
+ {
+ return false;
+ }
+ }
+ }
+ else if ( val instanceof byte[] )
{
- if ( !list.contains( attr.get( i ) ) )
+ Integer h = Integer.valueOf( Arrays.hashCode(
(byte[])val ) );
+
+ if ( !hash.containsKey( h ) )
{
return false;
}
+ else
+ {
+ Object val2 = hash.remove( h );
+
+ if ( !Arrays.equals( (byte[])val, (byte[])val2 ) )
+ {
+ return false;
+ }
+ }
}
- catch ( NamingException e )
+ else
{
- log.warn( "Failed to get an attribute from the
specifid attribute: " + attr, e );
return false;
}
}
-
- return true;
+
+ if ( hash.size() != 0 )
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+ catch ( NamingException ne )
+ {
+ log.warn( "Failed to get an attribute from the specifid
attribute: " + attr, ne );
+ return false;
+ }
}
}
+ /**
+ * @see Object#toString()
+ */
public String toString()
{
StringBuffer sb = new StringBuffer();
Copied:
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributesImpl.java
(from r493207,
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/LockableAttributesImpl.java)
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributesImpl.java?view=diff&rev=493916&p1=directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/LockableAttributesImpl.java&r1=493207&p2=directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributesImpl.java&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/LockableAttributesImpl.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributesImpl.java
Sun Jan 7 18:44:33 2007
@@ -31,6 +31,7 @@
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -40,37 +41,88 @@
* @author <a href="mailto:dev@xxxxxxxxxxxxxxxxxxxx">Apache Directory
Project</a>
* @version $Rev$
*/
-public class LockableAttributesImpl implements Attributes, Serializable
+public class AttributesImpl implements Attributes
{
- static transient final long serialVersionUID = -69864533495992471L;
+ static transient final long serialVersionUID = 1L;
+
+ /** This flag is used if the attribute name is not caseSensitive */
+ private boolean ignoreCase;
/**
* An holder to store <Id, Attribute> couples
- *
*/
private class Holder implements Serializable, Cloneable
{
static transient final long serialVersionUID = 1L;
+ // The user provided attribute ID
private String upId;
+
+ // The attribute. Should be an instance of LockableAttribute
private Attribute attribute;
+ /**
+ * Create a new holder for the given ID
+ * @param upId The attribute UP id
+ * @param attribute The attribute
+ */
private Holder( String upId, Attribute attribute )
{
this.upId = upId;
this.attribute = attribute;
}
+ /**
+ * @see Object#clone()
+ */
public Object clone() throws CloneNotSupportedException
{
Holder clone = (Holder)super.clone();
clone.upId = upId;
+
+ if ( attribute instanceof BasicAttribute )
+ {
+ // The BasicAttribute clone() method does not
+ // copy the values.
+ clone.attribute = new AttributeImpl( attribute.getID() );
+
+ try
+ {
+ NamingEnumeration values = attribute.getAll();
+
+ while ( values.hasMoreElements() )
+ {
+ Object value = values.nextElement();
+
+ if ( value instanceof byte[] )
+ {
+ // We have to clone the byte array, it's not
immutable.
+ byte[] oldValue = (byte[])value;
+ byte[] newValue = new byte[oldValue.length];
+
+ System.arraycopy( oldValue, 0, newValue, 0,
oldValue.length );
+ clone.attribute.add( newValue );
+ }
+ else
+ {
+ clone.attribute.add( value );
+ }
+ }
+ }
+ catch( NamingException ne )
+ {
+
+ }
+ }
clone.attribute = (Attribute)attribute.clone();
return clone;
}
+ /**
+ * @see Object#toString()
+ */
public String toString()
{
StringBuffer sb = new StringBuffer();
@@ -88,9 +140,11 @@
*/
public class AttributeIterator implements Iterator
{
+ /** The internal iterator */
private Iterator iterator;
- private AttributeIterator( LockableAttributesImpl attributes )
+ /** Create an attribute's iterator */
+ private AttributeIterator( AttributesImpl attributes )
{
iterator = attributes.keyMap.values().iterator();
}
@@ -151,11 +205,41 @@
// ------------------------------------------------------------------------
/**
- * Creates a LockableAttributes without a parent Lockable.
+ * Creates an Attributes
+ */
+ public AttributesImpl()
+ {
+ keyMap = new HashMap();
+ ignoreCase = true;
+ }
+
+ /**
+ * Creates an Attributes
*/
- public LockableAttributesImpl()
+ public AttributesImpl( boolean ignoreCase )
{
keyMap = new HashMap();
+ this.ignoreCase = ignoreCase;
+ }
+
+ /**
+ * Creates an Attributes with one Attribute
+ */
+ public AttributesImpl( String id, Object value )
+ {
+ keyMap = new HashMap();
+ put( id, value );
+ ignoreCase = true;
+ }
+
+ /**
+ * Creates an Attributes with one attribute
+ */
+ public AttributesImpl( String id, Object value, boolean ignoreCase )
+ {
+ keyMap = new HashMap();
+ put( id, value );
+ this.ignoreCase = ignoreCase;
}
// ------------------------------------------------------------------------
@@ -252,7 +336,7 @@
*/
public boolean isCaseIgnored()
{
- return true;
+ return ignoreCase;
}
@@ -351,7 +435,7 @@
*/
public Attribute put( String attrId, Object val )
{
- Attribute attr = new LockableAttributeImpl( attrId );
+ Attribute attr = new AttributeImpl( attrId );
attr.add( val );
String key = StringTools.toLowerCase( attrId );
@@ -367,6 +451,7 @@
* The non-null attribute to add. If the attribute set ignores
* the character case of its attribute ids, the case of attr's
* identifier is ignored.
+ * The store attribute is a clone of the given attribute.
* @return The Attribute with the same ID as attr that was previous in this
* attribute set; The new attr if no such attribute existed.
* @see #remove
@@ -374,8 +459,8 @@
public Attribute put( Attribute attr )
{
String key = StringTools.toLowerCase( attr.getID() );
- Attribute old = null;
- Attribute newAttr = attr;
+ Attribute old = null;
+ Attribute newAttr = attr;
if ( keyMap.containsKey( key ) )
{
@@ -386,24 +471,27 @@
old = attr;
}
- if ( attr instanceof BasicAttribute )
+ if ( attr instanceof AttributeImpl )
{
- newAttr = new LockableAttributeImpl( attr.getID() );
+ newAttr = attr;
+ }
+ else if ( attr instanceof BasicAttribute )
+ {
+ newAttr = new AttributeImpl( attr.getID() );
- try
- {
- NamingEnumeration values = attr.getAll();
-
- while ( values.hasMore() )
- {
- Object value = values.next();
- newAttr.add( value );
- }
- }
- catch ( NamingException ne )
- {
- // do nothing
- }
+ try
+ {
+ NamingEnumeration values = attr.getAll();
+
+ while ( values.hasMore() )
+ {
+ newAttr.add( AttributeUtils.cloneValue( values.next() ) );
+ }
+ }
+ catch ( NamingException ne )
+ {
+ // do nothing
+ }
}
keyMap.put( key, new Holder( attr.getID(), newAttr ) );
@@ -425,7 +513,6 @@
public Attribute remove( String attrId )
{
String key = StringTools.toLowerCase( attrId );
- Attribute old = null;
if ( keyMap.containsKey( key ) )
{
@@ -433,11 +520,17 @@
if ( holder != null )
{
- old = holder.attribute;
+ return holder.attribute;
}
+ else
+ {
+ return null;
+ }
+ }
+ else
+ {
+ return null;
}
-
- return old;
}
@@ -451,9 +544,9 @@
{
try
{
- LockableAttributesImpl clone =
(LockableAttributesImpl)super.clone();
+ AttributesImpl clone = (AttributesImpl)super.clone();
- clone.keyMap = (Map)((HashMap)keyMap).clone();
+ clone.keyMap = new HashMap( keyMap.size() );
Iterator keys = keyMap.keySet().iterator();
@@ -515,7 +608,7 @@
return true;
}
- if ( !( obj instanceof Attributes ) )
+ if ( ( obj == null ) || !( obj instanceof AttributesImpl ) )
{
return false;
}
@@ -536,7 +629,7 @@
while ( list.hasMoreElements() )
{
- Attribute attr = ( Attribute ) list.nextElement();
+ Attribute attr = ( Attribute )list.nextElement();
Attribute myAttr = get( attr.getID() );
if ( myAttr == null )
Added:
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModificationItemImpl.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModificationItemImpl.java?view=auto&rev=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModificationItemImpl.java
(added)
+++
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModificationItemImpl.java
Sun Jan 7 18:44:33 2007
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.ldap.message;
+
+import javax.naming.directory.Attribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+
+import org.apache.directory.shared.ldap.util.AttributeUtils;
+
+/**
+ *
+ * A specific version of this class, which do a transformation of a
+ * BasicAttribute to a AttributeImpl when created.
+ *
+ * This is necessary because BasicAttribute clone method do not do a
+ * deep clone, which is _bad_. AttributeImpl do a deep copy when
+ * cloning, which is _good_.
+ *
+ * @author <a href="mailto:dev@xxxxxxxxxxxxxxxxxxxx">Apache Directory
Project</a>
+ *
+ */
+public class ModificationItemImpl extends ModificationItem
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Create a modificationItemImpl
+ * @param modificationOp The modification operation : on of :
+ * - DirContext.ADD_ATTRIBUTE
+ * - DirContext.REPLACE_ATTRIBUTE
+ * - DirContext.REMOVE_ATTRIBUTE
+ * @param attribte The attribute to add, modify or remove
+ */
+ public ModificationItemImpl( int modificationOp, Attribute attribute )
+ {
+ super( modificationOp, AttributeUtils.toAttributeImpl( attribute ) );
+ }
+
+ /**
+ * Create a modificationItemImpl from a modificationItem
+ * @param modificationOp The modification operation : on of :
+ * - DirContext.ADD_ATTRIBUTE
+ * - DirContext.REPLACE_ATTRIBUTE
+ * - DirContext.REMOVE_ATTRIBUTE
+ * @param attribte The attribute to add, modify or remove
+ */
+ public ModificationItemImpl( ModificationItem modification )
+ {
+ super( modification.getModificationOp(),
+ AttributeUtils.toAttributeImpl( modification.getAttribute() ) );
+ }
+
+ /**
+ * Create a modificationItemImpl from a modificationItem
+ * @param modificationOp The modification operation : on of :
+ * - DirContext.ADD_ATTRIBUTE
+ * - DirContext.REPLACE_ATTRIBUTE
+ * - DirContext.REMOVE_ATTRIBUTE
+ * @param attribte The attribute to add, modify or remove
+ */
+ public ModificationItemImpl( ModificationItemImpl modification )
+ {
+ super( modification.getModificationOp(),
+ AttributeUtils.toAttributeImpl( modification.getAttribute() ) );
+ }
+
+ /**
+ * @return The modification operation
+ */
+ public int getModificationOp()
+ {
+ return super.getModificationOp();
+ }
+
+ /**
+ * Retrieves the attribute associated with this modification item.
+ *
+ * @return The non-null attribute to use for the modification.
+ */
+ public Attribute getAttribute()
+ {
+ return super.getAttribute();
+ }
+
+ /**
+ * @see Object#clone()
+ */
+ public Object clone() throws CloneNotSupportedException
+ {
+ return new ModificationItemImpl( getModificationOp(),
(Attribute)getAttribute().clone() );
+ }
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( "ModificationItem : \n" );
+
+ switch ( getModificationOp() )
+ {
+ case DirContext.ADD_ATTRIBUTE :
+ sb.append( " Add operation, ");
+ break;
+
+ case DirContext.REPLACE_ATTRIBUTE :
+ sb.append( " Replace operation, ");
+ break;
+
+ case DirContext.REMOVE_ATTRIBUTE :
+ sb.append( " Remove operation, ");
+ break;
+
+ default :
+ sb.append( " Unknown operation, ");
+ break;
+ }
+
+ sb.append( AttributeUtils.toString( " ", getAttribute() ) );
+
+ return sb.toString();
+ }
+}
Modified:
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequest.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequest.java?view=diff&rev=493916&r1=493915&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequest.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequest.java
Sun Jan 7 18:44:33 2007
@@ -22,7 +22,6 @@
import java.util.Collection;
-import javax.naming.directory.ModificationItem;
import org.apache.directory.shared.ldap.name.LdapDN;
@@ -141,7 +140,7 @@
* @param mod
* a ModificationItem to add.
*/
- void addModification( ModificationItem mod );
+ void addModification( ModificationItemImpl mod );
/**
@@ -151,5 +150,5 @@
* @param mod
* a ModificationItem to remove.
*/
- void removeModification( ModificationItem mod );
+ void removeModification( ModificationItemImpl mod );
}
Modified:
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequestImpl.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequestImpl.java?view=diff&rev=493916&r1=493915&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequestImpl.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequestImpl.java
Sun Jan 7 18:44:33 2007
@@ -23,20 +23,12 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashSet;
import java.util.Iterator;
-import java.util.Set;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.DirContext;
-import javax.naming.directory.ModificationItem;
import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.util.StringTools;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
@@ -49,9 +41,6 @@
{
static final long serialVersionUID = -505803669028990304L;
- /** The logger */
- private static final transient Logger log = LoggerFactory.getLogger(
ModifyRequestImpl.class );
-
/** Dn of the entry to modify or PDU's <b>object</b> field */
private LdapDN name;
@@ -127,7 +116,7 @@
* @param mod
* a ModificationItem to add.
*/
- public void addModification( ModificationItem mod )
+ public void addModification( ModificationItemImpl mod )
{
mods.add( mod );
}
@@ -140,7 +129,7 @@
* @param mod
* a ModificationItem to remove.
*/
- public void removeModification( ModificationItem mod )
+ public void removeModification( ModificationItemImpl mod )
{
mods.remove( mod );
}
@@ -227,9 +216,9 @@
for ( int ii = 0; ii < mods.size(); ii++ )
{
- ModificationItem item = ( ModificationItem ) list.next();
+ ModificationItemImpl item = ( ModificationItemImpl ) list.next();
- if ( !equals( ( ModificationItem ) mods.get( ii ), item ) )
+ if ( !equals( ( ModificationItemImpl ) mods.get( ii ), item ) )
{
return false;
}
@@ -249,7 +238,7 @@
* the second ModificationItem to compare
* @return true if the ModificationItems are equal, false otherwise
*/
- private boolean equals( ModificationItem item0, ModificationItem item1 )
+ private boolean equals( ModificationItemImpl item0, ModificationItemImpl
item1 )
{
if ( item0 == item1 )
{
@@ -267,59 +256,10 @@
return false;
}
- try
- {
- Attribute attr0 = item0.getAttribute();
- Attribute attr1 = item1.getAttribute();
-
- Set attrHash0 = new HashSet();
-
- NamingEnumeration iter0 = attr0.getAll();
-
- while ( iter0.hasMoreElements() )
- {
- attrHash0.add( iter0.next() );
- }
-
- NamingEnumeration iter1 = attr1.getAll();
+ Attribute attr0 = item0.getAttribute();
+ Attribute attr1 = item1.getAttribute();
- while ( iter1.hasMoreElements() )
- {
- Object value = iter1.next();
-
- if ( attrHash0.contains( value ) == false )
- {
- if ( value instanceof byte[] )
- {
- String sValue = StringTools.utf8ToString( ( byte[] )
value );
-
- if ( attrHash0.contains( sValue ) == false )
- {
- return false;
- }
- else
- {
- attrHash0.remove( sValue );
- continue;
- }
- }
- else
- {
- return false;
- }
- }
- else
- {
- attrHash0.remove( value );
- }
- }
-
- return ( attrHash0.size() == 0 );
- }
- catch ( NamingException ne )
- {
- return false;
- }
+ return attr0.equals( attr1 );
}
@@ -342,7 +282,7 @@
for ( int i = 0; i < mods.size(); i++ )
{
- ModificationItem modification = ( ModificationItem ) mods.get(
i );
+ ModificationItemImpl modification = ( ModificationItemImpl )
mods.get( i );
sb.append( " Modification[" ).append( i ).append(
"]\n" );
sb.append( " Operation : " );
@@ -364,42 +304,8 @@
}
sb.append( " Modification\n" );
-
- Attribute attribute = modification.getAttribute();
-
- try
- {
- sb.append( " Type : '" ).append(
attribute.getID() ).append( "'\n" );
- sb.append( " Vals\n" );
-
- for ( int j = 0; j < attribute.size(); j++ )
- {
- sb.append( " Val[" ).append( j
).append( "] : '" );
-
- Object attributeValue = attribute.get( j );
-
- if ( attributeValue instanceof byte[] )
- {
- sb.append( StringTools.utf8ToString( ( byte[] )
attributeValue ) ).append( '/' ).append(
- StringTools.dumpBytes( ( byte[] )
attributeValue ) );
- }
- else if ( attributeValue instanceof String )
- {
- sb.append( attributeValue );
- }
- else
- {
- sb.append( StringTools.dumpBytes(
StringTools.getBytesUtf8( attributeValue.toString() ) ) );
- }
-
- sb.append( "' \n" );
-
- }
- }
- catch ( NamingException ne )
- {
- log.error( "Naming exception while printing the '" +
attribute.getID() + "'" );
- }
+ sb.append( " " ).append(
modification.getAttribute() );
+
}
}
Modified:
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ResultCodeEnum.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ResultCodeEnum.java?view=diff&rev=493916&r1=493915&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ResultCodeEnum.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/ResultCodeEnum.java
Sun Jan 7 18:44:33 2007
@@ -24,8 +24,28 @@
import java.util.HashSet;
import java.util.Collections;
import java.util.Iterator;
-import javax.naming.*;
-import javax.naming.directory.*;
+
+import javax.naming.AuthenticationException;
+import javax.naming.AuthenticationNotSupportedException;
+import javax.naming.CommunicationException;
+import javax.naming.ContextNotEmptyException;
+import javax.naming.InvalidNameException;
+import javax.naming.LimitExceededException;
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.naming.NoPermissionException;
+import javax.naming.OperationNotSupportedException;
+import javax.naming.PartialResultException;
+import javax.naming.ServiceUnavailableException;
+import javax.naming.SizeLimitExceededException;
+import javax.naming.TimeLimitExceededException;
+import javax.naming.directory.AttributeInUseException;
+import javax.naming.directory.InvalidAttributeIdentifierException;
+import javax.naming.directory.InvalidAttributeValueException;
+import javax.naming.directory.InvalidSearchFilterException;
+import javax.naming.directory.NoSuchAttributeException;
+import javax.naming.directory.SchemaViolationException;
import org.apache.directory.shared.ldap.exception.LdapException;
import org.apache.directory.shared.ldap.util.ValuedEnum;
Modified:
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntry.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntry.java?view=diff&rev=493916&r1=493915&r2=493916
==============================================================================
(empty)
Modified:
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImpl.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImpl.java?view=diff&rev=493916&r1=493915&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImpl.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImpl.java
Sun Jan 7 18:44:33 2007
@@ -83,7 +83,7 @@
*/
public void setAttributes( Attributes attributes )
{
- this.attributes = attributes;
+ this.attributes = AttributeUtils.toAttributesImpl( attributes );
}
Modified:
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java?view=diff&rev=493916&r1=493915&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
Sun Jan 7 18:44:33 2007
@@ -30,10 +30,10 @@
import javax.naming.InvalidNameException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
import org.apache.commons.collections.MultiHashMap;
+import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -883,7 +883,7 @@
*/
public Attributes toAttributes()
{
- Attributes attributes = new BasicAttributes( true );
+ Attributes attributes = new AttributesImpl( true );
Attribute attribute = null;
switch ( nbAtavs )
@@ -892,7 +892,7 @@
break;
case 1 :
- attribute = new BasicAttribute( atavType, true );
+ attribute = new AttributeImpl( atavType );
attribute.add( atav.getValue() );
attributes.put( attribute );
break;
@@ -905,7 +905,7 @@
String type = ( String ) types.next();
List values = ( List ) atavTypes.get( type );
- attribute = new BasicAttribute( type, true );
+ attribute = new AttributeImpl( type );
Iterator iterValues = values.iterator();
Modified:
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java?view=diff&rev=493916&r1=493915&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
Sun Jan 7 18:44:33 2007
@@ -20,13 +20,16 @@
package org.apache.directory.shared.ldap.util;
-import org.apache.directory.shared.ldap.message.LockableAttributeImpl;
+import java.util.Arrays;
+
+import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
import org.apache.directory.shared.ldap.schema.AttributeType;
import org.apache.directory.shared.ldap.schema.Normalizer;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
-import javax.naming.directory.ModificationItem;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
@@ -40,6 +43,139 @@
public class AttributeUtils
{
/**
+ * Compare two values and return true if they are equal.
+ *
+ * @param value1 The first value
+ * @param value2 The second value
+ * @return true if both value are null or if they are equal.
+ */
+ public final static boolean equals( Object value1, Object value2 )
+ {
+ if ( value1 == value2 )
+ {
+ return true;
+ }
+
+ if ( value1 instanceof byte[] )
+ {
+ if ( value2 instanceof byte[] )
+ {
+ return Arrays.equals( (byte[])value1, (byte[])value2 );
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return value1.equals( value2 );
+ }
+ }
+
+ /**
+ * Clone the value. An attribute value is supposed to be either a String
+ * or a byte array. If it's a String, then we just return it ( as String
+ * is immutable, we don't need to copy it). If it's a bu=yte array, we
+ * create a new byte array and copy the bytes into it.
+ *
+ * @param value The value to clone
+ * @return The cloned value
+ */
+ public final static Object cloneValue( Object value )
+ {
+ // First copy the value
+ Object newValue = null;
+
+ if ( value instanceof byte[] )
+ {
+ newValue = ((byte[])value).clone();
+ }
+ else
+ {
+ newValue = value;
+ }
+
+ return newValue;
+ }
+
+ /**
+ * Switch from a BasicAttribute to a AttributeImpl. This is
+ * necessary to allow cloning to be correctly handled.
+ *
+ * @param attribute The attribute to transform
+ * @return A instance of AttributeImpl
+ */
+ public final static Attribute toAttributeImpl( Attribute attribute )
+ {
+ if ( attribute instanceof AttributeImpl )
+ {
+ // Just return the attribute
+ return attribute;
+ }
+ else
+ {
+ // Create a new AttributeImpl from the original attribute
+ AttributeImpl newAttribute = new AttributeImpl( attribute.getID()
);
+
+ try
+ {
+ NamingEnumeration values = attribute.getAll();
+
+ while ( values.hasMoreElements() )
+ {
+ newAttribute.add( cloneValue( values.next() ) );
+ }
+
+ return newAttribute;
+ }
+ catch ( NamingException ne )
+ {
+ return newAttribute;
+ }
+ }
+ }
+
+ /**
+ * Switch from a BasicAttributes to a AttributesImpl. This is
+ * necessary to allow cloning to be correctly handled.
+ *
+ * @param attributes The attributes to transform
+ * @return A instance of AttributesImpl
+ */
+ public final static Attributes toAttributesImpl( Attributes attributes )
+ {
+ if ( attributes instanceof AttributesImpl )
+ {
+ // Just return the attribute
+ return attributes;
+ }
+ else
+ {
+ // Create a new AttributesImpl from the original attribute
+ AttributesImpl newAttributes = new AttributesImpl(
attributes.isCaseIgnored() );
+
+ try
+ {
+ NamingEnumeration values = attributes.getAll();
+
+ while ( values.hasMoreElements() )
+ {
+ Attribute attribute = (Attribute)values.next();
+
+ newAttributes.put( toAttributeImpl( attribute ) );
+ }
+
+ return newAttributes;
+ }
+ catch ( NamingException ne )
+ {
+ return newAttributes;
+ }
+ }
+ }
+
+ /**
* Utility method to extract an attribute from Attributes object using
* all combinationos of the name including aliases.
*
@@ -81,7 +217,7 @@
* @param type the attributeType spec of the Attribute to extract
* @return the extract Attribute or null if no such attribute exists
*/
- public final static Attribute getAttribute( ModificationItem[] mods,
AttributeType type )
+ public final static Attribute getAttribute( ModificationItemImpl[] mods,
AttributeType type )
{
// optimization bypass to avoid cost of the loop below
if ( type.getNames().length == 1 )
@@ -231,7 +367,7 @@
}
else if ( attr0 == null )
{
- return new LockableAttributeImpl( attr1.getID() );
+ return new AttributeImpl( attr1.getID() );
}
else if ( attr1 == null )
{
@@ -246,7 +382,7 @@
id = attr0.getID();
}
- Attribute attr = new LockableAttributeImpl( id );
+ Attribute attr = new AttributeImpl( id );
if ( attr0 != null )
{
@@ -309,7 +445,7 @@
id = attr0.getID();
}
- Attribute attr = new LockableAttributeImpl( id );
+ Attribute attr = new AttributeImpl( id );
if ( attr0 != null )
{
@@ -341,60 +477,93 @@
* The attributes to print
* @return A string
*/
- public static String toString( String tabs, Attributes attributes )
+ public static String toString( String tabs, Attribute attribute )
{
StringBuffer sb = new StringBuffer();
- sb.append( tabs ).append( "Attributes\n" );
+ sb.append( tabs ).append( "Attribute\n" );
- if ( attributes != null )
+ if ( attribute != null )
{
- NamingEnumeration attributesIterator = attributes.getAll();
-
- while ( attributesIterator.hasMoreElements() )
+ sb.append( tabs ).append( " Type : '" ).append(
attribute.getID() ).append( "'\n" );
+
+ for ( int j = 0; j < attribute.size(); j++ )
{
- Attribute attribute = ( Attribute )
attributesIterator.nextElement();
-
- if ( attribute != null )
+
+ try
{
- sb.append( tabs ).append( " Type : '" ).append(
attribute.getID() ).append( "'\n" );
-
- for ( int j = 0; j < attribute.size(); j++ )
+ Object attr = attribute.get( j );
+
+ if ( attr != null )
{
-
- try
+ if ( attr instanceof String )
{
- Object attr = attribute.get( j );
-
- if ( attr != null )
- {
- if ( attr instanceof String )
- {
- sb.append( tabs ).append( " Val["
).append( j ).append( "] : " ).append( attr ).append(
- " \n" );
- }
- else if ( attr instanceof byte[] )
- {
- String string = StringTools.utf8ToString(
( byte[] ) attr );
-
- sb.append( tabs ).append( " Val["
).append( j ).append( "] : " );
- sb.append( string ).append( '/' );
- sb.append( StringTools.dumpBytes( ( byte[]
) attr ) );
- sb.append( " \n" );
- }
- else
- {
- sb.append( tabs ).append( " Val["
).append( j ).append( "] : " ).append( attr ).append(
- " \n" );
- }
- }
+ sb.append( tabs ).append( " Val[" ).append(
j ).append( "] : " ).append( attr ).append(
+ " \n" );
}
- catch ( NamingException ne )
+ else if ( attr instanceof byte[] )
{
- sb.append( "Bad attribute : " ).append(
ne.getMessage() );
+ String string = StringTools.utf8ToString( ( byte[]
) attr );
+
+ sb.append( tabs ).append( " Val[" ).append(
j ).append( "] : " );
+ sb.append( string ).append( '/' );
+ sb.append( StringTools.dumpBytes( ( byte[] ) attr
) );
+ sb.append( " \n" );
+ }
+ else
+ {
+ sb.append( tabs ).append( " Val[" ).append(
j ).append( "] : " ).append( attr ).append(
+ " \n" );
}
}
}
+ catch ( NamingException ne )
+ {
+ sb.append( "Bad attribute : " ).append( ne.getMessage() );
+ }
+ }
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Return a string representing the attributes
+ *
+ * @param attributes
+ * The attributes to print
+ * @return A string
+ */
+ public static String toString( Attribute attribute )
+ {
+ return toString( "", attribute );
+ }
+
+ /**
+ * Return a string representing the attributes with tabs in front of the
+ * string
+ *
+ * @param tabs
+ * Spaces to be added before the string
+ * @param attributes
+ * The attributes to print
+ * @return A string
+ */
+ public static String toString( String tabs, Attributes attributes )
+ {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( tabs ).append( "Attributes\n" );
+
+ if ( attributes != null )
+ {
+ NamingEnumeration attributesIterator = attributes.getAll();
+
+ while ( attributesIterator.hasMoreElements() )
+ {
+ Attribute attribute = ( Attribute )
attributesIterator.nextElement();
+
+ sb.append( tabs ).append( attribute.toString() );
}
}
Modified:
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/PropertiesUtils.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/PropertiesUtils.java?view=diff&rev=493916&r1=493915&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/PropertiesUtils.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/PropertiesUtils.java
Sun Jan 7 18:44:33 2007
@@ -28,13 +28,13 @@
import java.io.FileInputStream;
import java.io.StringReader;
-import javax.naming.directory.Attributes;
import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
import org.apache.directory.shared.ldap.NotImplementedException;
import org.apache.directory.shared.ldap.ldif.Entry;
import org.apache.directory.shared.ldap.ldif.LdifReader;
-import org.apache.directory.shared.ldap.message.LockableAttributesImpl;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
/**
@@ -688,7 +688,7 @@
{
if ( values == null )
{
- return new LockableAttributesImpl();
+ return new AttributesImpl();
}
return values;
Modified:
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java?view=diff&rev=493916&r1=493915&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java
Sun Jan 7 18:44:33 2007
@@ -27,8 +27,8 @@
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
import org.apache.directory.shared.asn1.ber.Asn1Decoder;
import org.apache.directory.shared.asn1.ber.IAsn1Container;
@@ -138,7 +138,7 @@
lVal2.add( "test3" );
typesVals.put( "attrs", lVal2 );
- BasicAttribute attributeValue = ( BasicAttribute ) attributes.get( "l"
);
+ Attribute attributeValue = (Attribute) attributes.get( "l" );
assertTrue( expectedTypes.contains(
attributeValue.getID().toLowerCase() ) );
@@ -154,7 +154,7 @@
vals.remove( value.toString() );
}
- attributeValue = ( BasicAttribute ) attributes.get( "attrs" );
+ attributeValue = ( Attribute ) attributes.get( "attrs" );
assertTrue( expectedTypes.contains(
attributeValue.getID().toLowerCase() ) );
@@ -625,7 +625,7 @@
assertEquals( 1, attributes.size() );
- BasicAttribute attributeValue = ( BasicAttribute ) attributes.get( "l"
);
+ Attribute attributeValue = ( Attribute ) attributes.get( "l" );
assertEquals( "l", attributeValue.getID().toLowerCase() );
@@ -717,7 +717,7 @@
assertEquals( 1, attributes.size() );
- BasicAttribute attributeValue = ( BasicAttribute ) attributes.get( "l"
);
+ Attribute attributeValue = ( Attribute ) attributes.get( "l" );
assertEquals( "l", attributeValue.getID().toLowerCase() );
Modified:
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java?view=diff&rev=493916&r1=493915&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java
Sun Jan 7 18:44:33 2007
@@ -25,8 +25,7 @@
import java.util.List;
import javax.naming.NamingException;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.ModificationItem;
+import javax.naming.directory.Attribute;
import org.apache.directory.shared.asn1.ber.Asn1Decoder;
import org.apache.directory.shared.asn1.ber.IAsn1Container;
@@ -39,6 +38,7 @@
import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
import org.apache.directory.shared.ldap.codec.modify.ModifyRequest;
import org.apache.directory.shared.ldap.message.Message;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
import org.apache.directory.shared.ldap.message.ModifyResponseImpl;
import org.apache.directory.shared.ldap.message.ResultCodeEnum;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -125,16 +125,16 @@
assertEquals( 2, modifications.size() );
- ModificationItem modification = ( ModificationItem )
modifications.get( 0 );
- BasicAttribute attributeValue = ( BasicAttribute )
modification.getAttribute();
+ ModificationItemImpl modification = ( ModificationItemImpl )
modifications.get( 0 );
+ Attribute attributeValue = ( Attribute ) modification.getAttribute();
assertEquals( "l", attributeValue.getID().toLowerCase() );
String attrValue = ( String ) attributeValue.get( 0 );
assertEquals( "Paris", attrValue );
- modification = ( ModificationItem ) modifications.get( 1 );
- attributeValue = ( BasicAttribute ) modification.getAttribute();
+ modification = ( ModificationItemImpl ) modifications.get( 1 );
+ attributeValue = ( Attribute ) modification.getAttribute();
assertEquals( "attrs", attributeValue.getID().toLowerCase() );
@@ -298,16 +298,16 @@
assertEquals( 2, modifications.size() );
- ModificationItem modification = ( ModificationItem )
modifications.get( 0 );
- BasicAttribute attributeValue = ( BasicAttribute )
modification.getAttribute();
+ ModificationItemImpl modification = ( ModificationItemImpl )
modifications.get( 0 );
+ Attribute attributeValue = ( Attribute ) modification.getAttribute();
assertEquals( "telephonenumber", attributeValue.getID().toLowerCase()
);
String attrValue = ( String ) attributeValue.get( 0 );
assertEquals( "1234567890", attrValue );
- modification = ( ModificationItem ) modifications.get( 1 );
- attributeValue = ( BasicAttribute ) modification.getAttribute();
+ modification = ( ModificationItemImpl ) modifications.get( 1 );
+ attributeValue = ( Attribute ) modification.getAttribute();
assertEquals( "cn", attributeValue.getID().toLowerCase() );
@@ -421,14 +421,14 @@
assertEquals( 3, modifications.size() );
- ModificationItem modification = ( ModificationItem )
modifications.get( 0 );
- BasicAttribute attributeValue = ( BasicAttribute )
modification.getAttribute();
+ ModificationItemImpl modification = ( ModificationItemImpl )
modifications.get( 0 );
+ Attribute attributeValue = ( Attribute ) modification.getAttribute();
assertEquals( "description", attributeValue.getID().toLowerCase() );
assertEquals( 0, attributeValue.size() );
- modification = ( ModificationItem ) modifications.get( 1 );
- attributeValue = ( BasicAttribute ) modification.getAttribute();
+ modification = ( ModificationItemImpl ) modifications.get( 1 );
+ attributeValue = ( Attribute ) modification.getAttribute();
String attrValue = ( String ) attributeValue.get( 0 );
@@ -436,8 +436,8 @@
assertEquals( "01234567890", attrValue );
- modification = ( ModificationItem ) modifications.get( 2 );
- attributeValue = ( BasicAttribute ) modification.getAttribute();
+ modification = ( ModificationItemImpl ) modifications.get( 2 );
+ attributeValue = ( Attribute ) modification.getAttribute();
attrValue = ( String ) attributeValue.get( 0 );
@@ -552,8 +552,8 @@
assertEquals( 2, modifications.size() );
- ModificationItem modification = ( ModificationItem )
modifications.get( 0 );
- BasicAttribute attributeValue = ( BasicAttribute )
modification.getAttribute();
+ ModificationItemImpl modification = ( ModificationItemImpl )
modifications.get( 0 );
+ Attribute attributeValue = ( Attribute ) modification.getAttribute();
assertEquals( "l", attributeValue.getID().toLowerCase() );
@@ -563,8 +563,8 @@
attrValue = ( String ) attributeValue.get( 1 );
assertEquals( "London", attrValue );
- modification = ( ModificationItem ) modifications.get( 1 );
- attributeValue = ( BasicAttribute ) modification.getAttribute();
+ modification = ( ModificationItemImpl ) modifications.get( 1 );
+ attributeValue = ( Attribute ) modification.getAttribute();
assertEquals( "attrs", attributeValue.getID().toLowerCase() );
@@ -1088,8 +1088,8 @@
assertEquals( 1, modifications.size() );
- ModificationItem modification = ( ModificationItem )
modifications.get( 0 );
- BasicAttribute attributeValue = ( BasicAttribute )
modification.getAttribute();
+ ModificationItemImpl modification = ( ModificationItemImpl )
modifications.get( 0 );
+ Attribute attributeValue = ( Attribute ) modification.getAttribute();
assertEquals( "l", attributeValue.getID().toLowerCase() );
assertEquals( 0, attributeValue.size() );
@@ -1171,8 +1171,8 @@
assertEquals( 1, modifications.size() );
- ModificationItem modification = ( ModificationItem )
modifications.get( 0 );
- BasicAttribute attributeValue = ( BasicAttribute )
modification.getAttribute();
+ ModificationItemImpl modification = ( ModificationItemImpl )
modifications.get( 0 );
+ Attribute attributeValue = ( Attribute ) modification.getAttribute();
assertEquals( "l", attributeValue.getID().toLowerCase() );
assertEquals( 0, attributeValue.size() );
@@ -1262,8 +1262,8 @@
assertEquals( 1, modifications.size() );
- ModificationItem modification = ( ModificationItem )
modifications.get( 0 );
- BasicAttribute attributeValue = ( BasicAttribute )
modification.getAttribute();
+ ModificationItemImpl modification = ( ModificationItemImpl )
modifications.get( 0 );
+ Attribute attributeValue = ( Attribute ) modification.getAttribute();
assertEquals( "l", attributeValue.getID().toLowerCase() );
assertEquals( 2, attributeValue.size() );
Modified:
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchRequestTest.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchRequestTest.java?view=diff&rev=493916&r1=493915&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchRequestTest.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchRequestTest.java
Sun Jan 7 18:44:33 2007
@@ -4295,7 +4295,6 @@
0x30, (byte)0x84, 0x00, 0x00, 0x00, 0x00
} );
- String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
// Allocate a BindRequest Container
Modified:
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryTest.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryTest.java?view=diff&rev=493916&r1=493915&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryTest.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryTest.java
Sun Jan 7 18:44:33 2007
@@ -26,8 +26,8 @@
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
import org.apache.directory.shared.asn1.ber.Asn1Decoder;
import org.apache.directory.shared.asn1.ber.IAsn1Container;
@@ -110,7 +110,7 @@
for ( int i = 0; i < partialAttributesList.size(); i++ )
{
- BasicAttribute attributeValue = ( BasicAttribute )
partialAttributesList.get( "objectclass" );
+ Attribute attributeValue = ( Attribute )
partialAttributesList.get( "objectclass" );
assertEquals( "objectClass".toLowerCase(),
attributeValue.getID().toLowerCase() );
@@ -220,7 +220,7 @@
for ( int i = 0; i < expectedAttributes.length; i++ )
{
- BasicAttribute attributeValue = ( BasicAttribute )
partialAttributesList.get( expectedAttributes[i] );
+ Attribute attributeValue = ( Attribute )
partialAttributesList.get( expectedAttributes[i] );
assertEquals( expectedAttributes[i].toLowerCase(),
attributeValue.getID().toLowerCase() );
@@ -329,7 +329,7 @@
for ( int i = 0; i < partialAttributesList.size(); i++ )
{
- BasicAttribute attributeValue = ( BasicAttribute )
partialAttributesList.get( "objectclass" );
+ Attribute attributeValue = ( Attribute )
partialAttributesList.get( "objectclass" );
assertEquals( "objectClass".toLowerCase(),
attributeValue.getID().toLowerCase() );
@@ -802,7 +802,7 @@
for ( int i = 0; i < partialAttributesList.size(); i++ )
{
- BasicAttribute attributeValue = ( BasicAttribute )
partialAttributesList.get( "objectclass" );
+ Attribute attributeValue = ( Attribute )
partialAttributesList.get( "objectclass" );
assertEquals( "objectClass".toLowerCase(),
attributeValue.getID().toLowerCase() );
@@ -885,12 +885,12 @@
assertEquals( 2, partialAttributesList.size() );
- BasicAttribute attributeValue = ( BasicAttribute )
partialAttributesList.get( "objectclass" );
+ Attribute attributeValue = ( Attribute ) partialAttributesList.get(
"objectclass" );
assertEquals( "objectClass".toLowerCase(),
attributeValue.getID().toLowerCase() );
NamingEnumeration values = attributeValue.getAll();
assertFalse( values.hasMore() );
- attributeValue = ( BasicAttribute ) partialAttributesList.get(
"objectclazz" );
+ attributeValue = ( Attribute ) partialAttributesList.get(
"objectclazz" );
assertEquals( "objectClazz".toLowerCase(),
attributeValue.getID().toLowerCase() );
values = attributeValue.getAll();
assertFalse( values.hasMore() );
@@ -972,7 +972,7 @@
for ( int i = 0; i < partialAttributesList.size(); i++ )
{
- BasicAttribute attributeValue = ( BasicAttribute )
partialAttributesList.get( "objectclass" );
+ Attribute attributeValue = ( Attribute )
partialAttributesList.get( "objectclass" );
assertEquals( "objectClass".toLowerCase(),
attributeValue.getID().toLowerCase() );
@@ -1066,7 +1066,7 @@
for ( int i = 0; i < partialAttributesList.size(); i++ )
{
- BasicAttribute attributeValue = ( BasicAttribute )
partialAttributesList.get( "objectclass" );
+ Attribute attributeValue = ( Attribute )
partialAttributesList.get( "objectclass" );
assertEquals( "objectClass".toLowerCase(),
attributeValue.getID().toLowerCase() );
@@ -1159,7 +1159,7 @@
for ( int i = 0; i < partialAttributesList.size(); i++ )
{
- BasicAttribute attributeValue = ( BasicAttribute )
partialAttributesList.get( "objectclass" );
+ Attribute attributeValue = ( Attribute )
partialAttributesList.get( "objectclass" );
assertEquals( "objectClass".toLowerCase(),
attributeValue.getID().toLowerCase() );
Modified:
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserImplTest.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserImplTest.java?view=diff&rev=493916&r1=493915&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserImplTest.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserImplTest.java
Sun Jan 7 18:44:33 2007
@@ -103,7 +103,6 @@
assertEquals(1, node.getChildren().size());
assertEquals(AbstractExprNode.AND, node.getOperator());
}
-
public void testOrFilter() throws IOException, ParseException {
BranchNode node = (BranchNode) parser
.parse("(| ( ou ~= people ) (age>=30) ) ");
Modified:
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java?view=diff&rev=493916&r1=493915&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java
Sun Jan 7 18:44:33 2007
@@ -30,10 +30,10 @@
import javax.naming.directory.Attribute;
import javax.naming.directory.DirContext;
-import javax.naming.directory.ModificationItem;
import javax.naming.ldap.Control;
import javax.naming.NamingException;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
import org.apache.directory.shared.ldap.util.StringTools;
/**
@@ -1217,20 +1217,20 @@
// "add: postaladdress"
// "postaladdress: 123 Anystreet $ Sunnyvale, CA $ 94086"
- ModificationItem item = (ModificationItem) modifs.get( 0 );
+ ModificationItemImpl item = (ModificationItemImpl) modifs.get( 0 );
assertEquals( DirContext.ADD_ATTRIBUTE, item.getModificationOp() );
assertEquals( values[4][1][0], item.getAttribute().getID() );
assertEquals( values[4][1][1], item.getAttribute().get( 0 ) );
// "delete: description\n" +
- item = (ModificationItem) modifs.get( 1 );
+ item = (ModificationItemImpl) modifs.get( 1 );
assertEquals( DirContext.REMOVE_ATTRIBUTE, item.getModificationOp() );
assertEquals( values[4][2][0], item.getAttribute().getID() );
// "replace: telephonenumber"
// "telephonenumber: +1 408 555 1234"
// "telephonenumber: +1 408 555 5678"
- item = (ModificationItem) modifs.get( 2 );
+ item = (ModificationItemImpl) modifs.get( 2 );
assertEquals( DirContext.REPLACE_ATTRIBUTE, item.getModificationOp() );
assertEquals( values[4][3][0], item.getAttribute().getID() );
assertEquals( values[4][3][1], item.getAttribute().get( 0 ) );
@@ -1238,7 +1238,7 @@
// "delete: facsimiletelephonenumber"
// "facsimiletelephonenumber: +1 408 555 9876"
- item = (ModificationItem) modifs.get( 3 );
+ item = (ModificationItemImpl) modifs.get( 3 );
assertEquals( DirContext.REMOVE_ATTRIBUTE, item.getModificationOp() );
assertEquals( values[4][4][0], item.getAttribute().getID() );
assertEquals( values[4][4][1], item.getAttribute().get( 0 ) );
@@ -1251,12 +1251,12 @@
assertEquals( values[5][0][1], entry.getDn() );
// "replace: postaladdress"
- item = (ModificationItem) modifs.get( 0 );
+ item = (ModificationItemImpl) modifs.get( 0 );
assertEquals( DirContext.REPLACE_ATTRIBUTE, item.getModificationOp() );
assertEquals( values[5][1][0], item.getAttribute().getID() );
// "delete: description"
- item = (ModificationItem) modifs.get( 1 );
+ item = (ModificationItemImpl) modifs.get( 1 );
assertEquals( DirContext.REMOVE_ATTRIBUTE, item.getModificationOp() );
assertEquals( values[5][2][0], item.getAttribute().getID() );
}
Modified:
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/message/AddRequestImplTest.java
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/message/AddRequestImplTest.java?view=diff&rev=493916&r1=493915&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/message/AddRequestImplTest.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/message/AddRequestImplTest.java
Sun Jan 7 18:44:33 2007
@@ -32,8 +32,8 @@
import org.apache.directory.shared.ldap.message.AddRequest;
import org.apache.directory.shared.ldap.message.AddRequestImpl;
import org.apache.directory.shared.ldap.message.Control;
-import org.apache.directory.shared.ldap.message.LockableAttributeImpl;
-import org.apache.directory.shared.ldap.message.LockableAttributesImpl;
+import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
import org.apache.directory.shared.ldap.message.MessageException;
import org.apache.directory.shared.ldap.message.MessageTypeEnum;
import org.apache.directory.shared.ldap.message.ResultResponse;
@@ -55,9 +55,9 @@
* the id for the attribute
* @return the LockableAttributeImpl assembled for testing
*/
- private LockableAttributeImpl getAttribute( String id )
+ private AttributeImpl getAttribute( String id )
{
- LockableAttributeImpl attr = new LockableAttributeImpl( id );
+ AttributeImpl attr = new AttributeImpl( id );
attr.add( "value0" );
attr.add( "value1" );
attr.add( "value2" );
@@ -70,9 +70,9 @@
*
* @return
*/
- private LockableAttributesImpl getAttributes()
+ private AttributesImpl getAttributes()
{
- LockableAttributesImpl attrs = new LockableAttributesImpl();
+ AttributesImpl attrs = new AttributesImpl();
attrs.put( getAttribute( "attr0" ) );
attrs.put( getAttribute( "attr1" ) );
attrs.put( getAttribute( "attr2" ) );
Copied:
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/message/AttributeImplTest.java
(from r493207,
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/message/LockableAttributeImplTest.java)
URL:
http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/message/AttributeImplTest.java?view=diff&rev=493916&p1=directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/message/LockableAttributeImplTest.java&r1=493207&p2=directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/message/AttributeImplTest.java&r2=493916
==============================================================================
---
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/message/LockableAttributeImplTest.java
(original)
+++
directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/message/AttributeImplTest.java
Sun Jan 7 18:44:33 2007
@@ -20,12 +20,15 @@
package org.apache.directory.shared.ldap.message;
-import junit.framework.TestCase;
-
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
import javax.naming.directory.Attribute;
-import javax.naming.directory.BasicAttribute;
-import org.apache.directory.shared.ldap.message.LockableAttributeImpl;
+import junit.framework.TestCase;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.util.StringTools;
/**
@@ -34,14 +37,14 @@
* @author <a href="mailto:dev@xxxxxxxxxxxxxxxxxxxx"> Apache Directory
Project</a>
* $Rev$
*/
-public class LockableAttributeImplTest extends TestCase
+public class AttributeImplTest extends TestCase
{
/**
* Creates and populates a LockableAttributeImpl instance for tests.
*/
- private LockableAttributeImpl getAttribute()
+ private AttributeImpl getAttribute()
{
- LockableAttributeImpl attr = new LockableAttributeImpl( "test-attr1" );
+ AttributeImpl attr = new AttributeImpl( "test-attr1" );
attr.add( "value0" );
attr.add( "value1" );
attr.add( "value2" );
@@ -54,7 +57,7 @@
*/
public void testEqualsSameObj()
{
- LockableAttributeImpl attr = getAttribute();
+ AttributeImpl attr = getAttribute();
assertTrue( "same object should be equal", attr.equals( attr ) );
}
@@ -64,8 +67,8 @@
*/
public void testEqualsExactCopy()
{
- LockableAttributeImpl attr0 = getAttribute();
- LockableAttributeImpl attr1 = getAttribute();
+ AttributeImpl attr0 = getAttribute();
+ AttributeImpl attr1 = getAttribute();
assertTrue( "exact copies should be equal", attr0.equals( attr1 ) );
assertTrue( "exact copies should be equal", attr1.equals( attr0 ) );
}
@@ -76,8 +79,8 @@
*/
public void testNotEqualDiffId()
{
- LockableAttributeImpl attr0 = getAttribute();
- LockableAttributeImpl attr1 = new LockableAttributeImpl( "test-attr2"
);
+ AttributeImpl attr0 = getAttribute();
+ AttributeImpl attr1 = new AttributeImpl( "test-attr2" );
attr1.add( "value0" );
attr1.add( "value1" );
attr1.add( "value2" );
@@ -91,8 +94,8 @@
*/
public void testNotEqualDiffCasedId()
{
- LockableAttributeImpl attr0 = getAttribute();
- LockableAttributeImpl attr1 = new LockableAttributeImpl( "TEST-attr1"
);
+ AttributeImpl attr0 = getAttribute();
+ AttributeImpl attr1 = new AttributeImpl( "TEST-attr1" );
attr1.add( "value0" );
attr1.add( "value1" );
attr1.add( "value2" );
@@ -106,8 +109,8 @@
*/
public void testNotEqualDiffValues()
{
- LockableAttributeImpl attr0 = getAttribute();
- LockableAttributeImpl attr1 = new LockableAttributeImpl( "test-attr1"
);
+ AttributeImpl attr0 = getAttribute();
+ AttributeImpl attr1 = new AttributeImpl( "test-attr1" );
attr1.add( "value0" );
attr1.add( "value1" );
assertFalse( "Attributes with different values should not be equal",
attr0.equals( attr1 ) );
@@ -129,8 +132,8 @@
*/
public void testNotEqualWithReplicatedValues()
{
- LockableAttributeImpl attr0 = getAttribute();
- LockableAttributeImpl attr1 = new LockableAttributeImpl( "test-attr1"
);
+ AttributeImpl attr0 = getAttribute();
+ AttributeImpl attr1 = new AttributeImpl( "test-attr1" );
attr1.add( "value0" );
attr1.add( "value1" );
assertFalse( "Attributes with different values should not be equal",
attr0.equals( attr1 ) );
@@ -141,8 +144,8 @@
assertTrue( "Attributes with same values should be equal",
attr1.equals( attr0 ) );
attr1.add( "value2" );
- assertFalse( "Attributes with different values should not be equal",
attr0.equals( attr1 ) );
- assertFalse( "Attributes with different values should not be equal",
attr1.equals( attr0 ) );
+ assertTrue( "Attributes with different values should not be equal",
attr0.equals( attr1 ) );
+ assertTrue( "Attributes with different values should not be equal",
attr1.equals( attr0 ) );
}
@@ -154,8 +157,8 @@
*/
public void testNotEqualDiffImpl()
{
- LockableAttributeImpl attr0 = getAttribute();
- Attribute attr1 = new BasicAttribute( "test-attr1" );
+ AttributeImpl attr0 = getAttribute();
+ Attribute attr1 = new AttributeImpl( "test-attr1" );
attr1.add( "value0" );
attr1.add( "value1" );
assertFalse( "Attributes with different values should not be equal",
attr0.equals( attr1 ) );
@@ -175,9 +178,121 @@
public void testContains()
{
- LockableAttributeImpl attr = getAttribute();
+ AttributeImpl attr = getAttribute();
assertTrue( attr.contains( "value0" ) );
assertTrue( attr.contains( "value1" ) );
assertTrue( attr.contains( "value2" ) );
+ }
+
+ // Test the clone operation
+ public void testCloneAttribute() throws NamingException
+ {
+ Attribute attr = new AttributeImpl( "test" );
+
+ String zero = "zero";
+ attr.add( zero );
+
+ String one = "one";
+ attr.add( one );
+
+ byte[] two = StringTools.getBytesUtf8( "two" );
+ attr.add( two );
+
+ byte[] three = StringTools.getBytesUtf8( "three" );
+ attr.add( three );
+
+ Object[] allValues = new Object[] { zero, one, two, three };
+
+ Attribute clone = (Attribute)attr.clone();
+
+ // Test the atomic elements
+ assertTrue( clone instanceof AttributeImpl );
+ assertEquals( 4, clone.size() );
+ assertEquals( "test", clone.getID() );
+
+ // Now test the values
+ NamingEnumeration values = clone.getAll();
+
+ int i = 0;
+
+ while ( values.hasMoreElements() )
+ {
+ Object value = values.next();
+
+ if ( value instanceof String )
+ {
+ assertEquals( allValues[i++], value );
+ }
+ else
+ {
+ byte[] v = (byte[])value;
+
+ // The content should be equal
+ assertTrue( ArrayUtils.isEquals( allValues[i], v ) );
+
+ // but not the container
+ assertNotSame( allValues[i++], value );
+ }
+ }
+
+ // Check that if we change the content, the cloned attribute
+ // is still the same.
+ two[1] = 'o';
+ attr.set( 2, two );
+
+ // The initial attribute should be modified
+ Object attrTwo = attr.get( 2 );
+ assertNotSame( two, attrTwo );
+ assertTrue( ArrayUtils.isEquals( two, attrTwo ) );
+
+ // but the cloned attribute should remain the same
+ Object clonedTwo = clone.get( 2 );
+ assertNotSame( two, clonedTwo );
+ assertFalse( ArrayUtils.isEquals( two, clonedTwo ) );
+
+ // Remove a value from the original attribute
+ three = (byte[])attr.remove( 3 );
+
+ // Check that it does not have modified the cloned attribute
+ assertEquals( 4, clone.size() );
+
+ // The content should be equal
+ assertTrue( ArrayUtils.isEquals( three, clone.get( 3 ) ) );
+
+ // but not the container
+ assertNotSame( three, clone.get( 3 ) );
+ }
+
+ public void testEquals()
+ {
+ Attribute attr = new AttributeImpl( "test" );
+
+ String zero = "zero";
+ attr.add( zero );
+
+ String one = "one";
+ attr.add( one );
+
+ byte[] two = StringTools.getBytesUtf8( "two" );
+ attr.add( two );
+
+ byte[] three = StringTools.getBytesUtf8( "three" );
+ attr.add( three );
+
+ Attribute clone = (Attribute)attr.clone();
+
+ // Check that both attributes are equals
+ assertTrue( attr.equals( clone ) );
+
+ clone.set( 3, "three" );
+ assertFalse( attr.equals( clone ) );
+
+ two[1] = 'o';
+ attr.set( 2, two );
+
+ assertFalse( attr.equals( clone ) );
+
+ attr.set( 2, "two" );
+ assertFalse( attr.equals( clone ) );
}
}
|
|