You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2007/12/07 05:29:10 UTC

svn commit: r601982 [3/3] - in /directory: apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/ apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/changelog/ apacheds/branches/bigbang/core/src/...

Modified: directory/apacheds/branches/bigbang/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultSyntaxRegistry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultSyntaxRegistry.java?rev=601982&r1=601981&r2=601982&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultSyntaxRegistry.java (original)
+++ directory/apacheds/branches/bigbang/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultSyntaxRegistry.java Thu Dec  6 20:29:07 2007
@@ -41,10 +41,10 @@
 public class DefaultSyntaxRegistry implements SyntaxRegistry
 {
     /** static class logger */
-    private final static Logger log = LoggerFactory.getLogger( DefaultSyntaxRegistry.class );
+    private static final Logger LOG = LoggerFactory.getLogger( DefaultSyntaxRegistry.class );
     
     /** Speedup for DEBUG mode */
-    private static final boolean IS_DEBUG = log.isDebugEnabled();
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
     
     /** a map of entries using an OID for the key and a Syntax for the value */
     private final Map<String,Syntax> byOid;
@@ -57,9 +57,12 @@
     // ------------------------------------------------------------------------
 
     /**
-     * Creates a BootstrapSyntaxRegistry.
+     * Creates a DefaultSyntaxRegistry.
+     *
+     * @param registry used by this registry for OID to name resolution of
+     * dependencies and to automatically register and unregister it's aliases and OIDs
      */
-    public DefaultSyntaxRegistry(OidRegistry registry)
+    public DefaultSyntaxRegistry( OidRegistry registry )
     {
         this.oidRegistry = registry;
         this.byOid = new HashMap<String,Syntax>();
@@ -81,14 +84,13 @@
             
             if ( IS_DEBUG )
             {
-                log.debug( "looked up using id '" + id + "': " + syntax );
+                LOG.debug( "looked up using id '" + id + "': " + syntax );
             }
             
             return syntax;
         }
 
-        NamingException fault = new NamingException( "Unknown syntax OID " + id );
-        throw fault;
+        throw new NamingException( "Unknown syntax OID " + id );
     }
 
 
@@ -96,9 +98,8 @@
     {
         if ( byOid.containsKey( syntax.getOid() ) )
         {
-            NamingException e = new NamingException( "syntax w/ OID " + syntax.getOid()
+            throw new NamingException( "syntax w/ OID " + syntax.getOid()
                 + " has already been registered!" );
-            throw e;
         }
 
         if ( syntax.getName() != null )
@@ -114,7 +115,7 @@
         
         if ( IS_DEBUG )
         {
-            log.debug( "registered syntax: " + syntax );
+            LOG.debug( "registered syntax: " + syntax );
         }
     }
 

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java?rev=601982&r1=601981&r2=601982&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java Thu Dec  6 20:29:07 2007
@@ -1563,8 +1563,7 @@
      * @throws InvalidNameException If the DN is invalid.
      * @throws NamingException If something went wrong.
      */
-    public static LdapDN normalize( LdapDN dn, Map<String, OidNormalizer> oidsMap ) throws InvalidNameException,
-        NamingException
+    public static LdapDN normalize( LdapDN dn, Map<String, OidNormalizer> oidsMap ) throws NamingException
     {
         if ( ( dn == null ) || ( dn.size() == 0 ) || ( oidsMap == null ) || ( oidsMap.size() == 0 ) )
         {
@@ -1606,7 +1605,7 @@
      * @throws InvalidNameException If the DN is invalid.
      * @throws NamingException If something went wrong.
      */
-    public LdapDN normalize( Map<String, OidNormalizer> oidsMap ) throws InvalidNameException, NamingException
+    public LdapDN normalize( Map<String, OidNormalizer> oidsMap ) throws NamingException
     {
         if ( ( oidsMap == null ) || ( oidsMap.size() == 0 ) )
         {

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java?rev=601982&r1=601981&r2=601982&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java Thu Dec  6 20:29:07 2007
@@ -93,7 +93,7 @@
      * @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 )
+    public static final boolean equals( Object value1, Object value2 )
     {
         if ( value1 == value2 )
         {
@@ -116,7 +116,8 @@
             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
@@ -126,7 +127,7 @@
      * @param value The value to clone
      * @return The cloned value
      */
-    public final static Object cloneValue( Object value )
+    public static Object cloneValue( Object value )
     {
         // First copy the value
         Object newValue = null;
@@ -143,6 +144,7 @@
         return newValue;
     }
 
+
     /**
      * Switch from a BasicAttribute to a AttributeImpl. This is
      * necessary to allow cloning to be correctly handled.
@@ -150,7 +152,7 @@
      * @param attribute The attribute to transform
      * @return A instance of AttributeImpl
      */
-    public final static Attribute toAttributeImpl( Attribute attribute )
+    public static final Attribute toAttributeImpl( Attribute attribute )
     {
         if ( attribute instanceof AttributeImpl )
         {
@@ -179,7 +181,8 @@
             }
         }
     }
-    
+
+
     /**
      * Switch from a BasicAttributes to a AttributesImpl. This is
      * necessary to allow cloning to be correctly handled.
@@ -187,7 +190,7 @@
      * @param attributes The attributes to transform
      * @return A instance of AttributesImpl
      */
-    public final static Attributes toAttributesImpl( Attributes attributes )
+    public static final Attributes toAttributesImpl( Attributes attributes )
     {
         if ( attributes instanceof AttributesImpl )
         {
@@ -218,7 +221,8 @@
             }
         }
     }
-    
+
+
     /**
      * Utility method to extract an attribute from Attributes object using
      * all combinationos of the name including aliases.
@@ -227,7 +231,7 @@
      * @param type the attribute type specification
      * @return an Attribute with matching the attributeType spec or null
      */
-    public final static Attribute getAttribute( Attributes attrs, AttributeType type )
+    public static final Attribute getAttribute( Attributes attrs, AttributeType type )
     {
         // check if the attribute's OID is used
         Attribute attr = attrs.get( type.getOid() );
@@ -270,7 +274,7 @@
      * @param type the attributeType spec of the Attribute to extract
      * @return the modification item on the attributeType specified
      */
-    public final static ModificationItem getModificationItem( ModificationItem[] mods, AttributeType type )
+    public static final ModificationItem getModificationItem( ModificationItem[] mods, AttributeType type )
     {
         // optimization bypass to avoid cost of the loop below
         if ( type.getNames().length == 1 )
@@ -316,7 +320,7 @@
      * @param type the attributeType spec of the Attribute to extract
      * @return the modification item on the attributeType specified
      */
-    public final static ModificationItem getModificationItem( List<ModificationItemImpl> mods, AttributeType type )
+    public static final ModificationItem getModificationItem( List<ModificationItemImpl> mods, AttributeType type )
     {
         // optimization bypass to avoid cost of the loop below
         if ( type.getNames().length == 1 )
@@ -362,7 +366,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 static final Attribute getAttribute( ModificationItem[] mods, AttributeType type )
     {
         ModificationItem mod = getModificationItem( mods, type );
         
@@ -382,7 +386,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( List<ModificationItemImpl> mods, AttributeType type )
+    public static Attribute getAttribute( List<ModificationItemImpl> mods, AttributeType type )
     {
         ModificationItem mod = getModificationItem( mods, type );
         
@@ -404,7 +408,7 @@
      * @return <code>true</code> if the value exists in the attribute</code>
      * @throws NamingException If something went wrong while accessing the data
      */
-    public final static boolean containsValue( Attribute attr, Object compared, AttributeType type ) throws NamingException
+    public static boolean containsValue( Attribute attr, Object compared, AttributeType type ) throws NamingException
     {
         // quick bypass test
         if ( attr.contains( compared ) )
@@ -517,6 +521,7 @@
         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[],
@@ -527,7 +532,7 @@
      * @return true if the value is present in the attribute
      * @throws NamingException
      */
-    public final static boolean containsValueCaseIgnore( Attribute attr, Object value )
+    public static boolean containsValueCaseIgnore( Attribute attr, Object value )
     {
         // quick bypass test
         if ( attr.contains( value ) )
@@ -758,6 +763,7 @@
         return attr;
     }
 
+
     /**
      * Check if the attributes is a BasicAttributes, and if so, switch
      * the case sensitivity to false to avoid tricky problems in the server.
@@ -867,6 +873,7 @@
         return sb.toString();
     }
 
+
     /**
      * Return a string representing the attribute
      * 
@@ -879,6 +886,7 @@
         return toString( "", attribute );
     }
 
+
     /**
      * Return a string representing the attributes with tabs in front of the
      * string
@@ -892,7 +900,6 @@
     public static String toString( String tabs, Attributes attributes )
     {
         StringBuffer sb = new StringBuffer();
-
         sb.append( tabs ).append( "Attributes\n" );
 
         if ( attributes != null )
@@ -902,14 +909,14 @@
             while ( attributesIterator.hasMoreElements() )
             {
                 Attribute attribute = ( Attribute ) attributesIterator.nextElement();
-    
                 sb.append( tabs ).append( attribute.toString() );
             }
         }
         
         return sb.toString();
     }
-    
+
+
     /**
      * Parse attribute's options :
      * 
@@ -938,7 +945,8 @@
             }
         }
     }
-    
+
+
     /**
      * Parse a number :
      * 
@@ -1030,7 +1038,8 @@
             }
         }
     }
-    
+
+
     /**
      * Parse an attribute. The grammar is :
      * attributedescription = attributetype options
@@ -1269,5 +1278,128 @@
 
                 break;
         }
+    }
+
+
+    /**
+     * Check if an attribute contains a specific value and remove it using the associated
+     * matchingRule for the attribute type supplied.
+     *
+     * @param attr the attribute we are searching in
+     * @param compared the object we are looking for
+     * @param type the attribute type
+     * @return the value removed from the attribute, otherwise null
+     * @throws NamingException if something went wrong while removing the value
+     */
+    public static Object removeValue( Attribute attr, Object compared, AttributeType type ) throws NamingException
+    {
+        // quick bypass test
+        if ( attr.contains( compared ) )
+        {
+            return attr.remove( compared );
+        }
+
+        MatchingRule matchingRule = type.getEquality();
+        Normalizer normalizer;
+
+        if ( matchingRule != null )
+        {
+            normalizer = type.getEquality().getNormalizer();
+        }
+        else
+        {
+            normalizer = new NoOpNormalizer();
+        }
+
+        if ( type.getSyntax().isHumanReadable() )
+        {
+            String comparedStr = ( String ) normalizer.normalize( compared );
+
+            for ( NamingEnumeration<?> values = attr.getAll(); values.hasMoreElements(); /**/ )
+            {
+                String value = ( String ) values.nextElement();
+                if ( comparedStr.equals( normalizer.normalize( value ) ) )
+                {
+                    return attr.remove( value );
+                }
+            }
+        }
+        else
+        {
+            byte[] comparedBytes = null;
+
+            if ( compared instanceof String )
+            {
+                if ( ( ( String ) compared ).length() < 3 )
+                {
+                    return null;
+                }
+
+                // Tansform the String to a byte array
+                int state = 1;
+                comparedBytes = new byte[( ( String ) compared ).length() / 3];
+                int pos = 0;
+
+                for ( char c:((String)compared).toCharArray() )
+                {
+                    switch ( state )
+                    {
+                        case 1 :
+                            if ( c != '\\' )
+                            {
+                                return null;
+                            }
+
+                            state++;
+                            break;
+
+                        case 2 :
+                            int high = StringTools.getHexValue( c );
+
+                            if ( high == -1 )
+                            {
+                                return null;
+                            }
+
+                            comparedBytes[pos] = (byte)(high << 4);
+
+                            state++;
+                            break;
+
+                        case 3 :
+                            int low = StringTools.getHexValue( c );
+
+                            if ( low == -1 )
+                            {
+                                return null;
+                            }
+
+                            comparedBytes[pos] += (byte)low;
+                            pos++;
+
+                            state = 1;
+                    }
+                }
+            }
+            else
+            {
+                comparedBytes = ( byte[] ) compared;
+            }
+
+            for ( NamingEnumeration<?> values = attr.getAll(); values.hasMoreElements(); /**/ )
+            {
+                Object value = values.nextElement();
+
+                if ( value instanceof byte[] )
+                {
+                    if ( ArrayUtils.isEquals( comparedBytes, value ) )
+                    {
+                        return attr.remove( value );
+                    }
+                }
+            }
+        }
+
+        return null;
     }
 }