directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r498449 - in /directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap: schema/AbstractSchemaObject.java util/AttributeUtils.java
Date Sun, 21 Jan 2007 20:47:12 GMT
Author: elecharny
Date: Sun Jan 21 12:47:11 2007
New Revision: 498449

URL: http://svn.apache.org/viewvc?view=rev&rev=498449
Log:
src/main/java/org/apache/directory/shared/ldap/schema/AbstractSchemaObject.java :
Modified the toString() method for better lisibility in debug mode

src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java :
Added a method containsValueCaseIgnore( Attribute attr, Object value ) which search for a
value in
an attribute, case insensitive. This method should be removed, and we should use the static
method
containsValue( Attribute attr, Object compared, AttributeType type ) instead. But in 1.0,
there is
two problems : 
1) We don't always have access to the AttributeType when we need to call this method (because
we don't
have access to the registries)
2) It throws a NamingException and the caller does not handle this exception.
So the added method can be used for Attribute which are not caseSensitive, like ObjectClass.


Modified:
    directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AbstractSchemaObject.java
    directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java

Modified: directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AbstractSchemaObject.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AbstractSchemaObject.java?view=diff&rev=498449&r1=498448&r2=498449
==============================================================================
--- directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AbstractSchemaObject.java
(original)
+++ directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AbstractSchemaObject.java
Sun Jan 21 12:47:11 2007
@@ -316,6 +316,6 @@
      */
     public String toString()
     {
-        return oid.toString();
+        return "<" + oid.toString() + ", " + names[0] + ">";
     }
 }

Modified: directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java?view=diff&rev=498449&r1=498448&r2=498449
==============================================================================
--- directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
(original)
+++ directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
Sun Jan 21 12:47:11 2007
@@ -293,6 +293,73 @@
         return false;
     }
 
+    /**
+     * Check if an attribute contains a value. The test is case insensitive,
+     * and the value is supposed to be a String. If the value is a byte[],
+     * then the case sensitivity is useless.
+     * 
+     * @param attr The attribute to check
+     * @param value The value to look for
+     * @return true if the value is present in the attribute
+     * @throws NamingException 
+     */
+    public final static boolean containsValueCaseIgnore( Attribute attr, Object value )
+    {
+        // quick bypass test
+        if ( attr.contains( value ) )
+        {
+            return true;
+        }
+
+        try
+        {
+            if ( value instanceof String )
+            {
+                String strVal = (String)value;
+                
+                NamingEnumeration attrVals = attr.getAll();
+                
+                while ( attrVals.hasMoreElements() )
+                {
+                    Object attrVal = attrVals.nextElement();
+                    
+                    if ( attrVal instanceof String )
+                    {
+                        if ( strVal.equalsIgnoreCase( (String)attrVal ) )
+                        {
+                            return true;
+                        }
+                    }
+                }
+            }
+            else
+            {
+                byte[] valueBytes = ( byte[] )value;
+                
+                NamingEnumeration attrVals = attr.getAll();
+                
+                while ( attrVals.hasMoreElements() )
+                {
+                    Object attrVal = attrVals.nextElement();
+                    
+                    if ( attrVal instanceof byte[] )
+                    {
+                        if ( Arrays.equals( (byte[])attrVal, valueBytes ) )
+                        {
+                            return true;
+                        }
+                        
+                    }
+                }
+            }
+        }
+        catch (NamingException ne )
+        {
+            return false;
+        }
+
+        return false;
+    }
 
     public static boolean containsAnyValues( Attribute attr, Object[] compared, AttributeType
type )
         throws NamingException



Mime
View raw message