You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2012/02/07 16:29:01 UTC

svn commit: r1241488 - in /directory: apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/schema/ shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/ shared/trunk/ldap/model/src/main/java/org/ap...

Author: elecharny
Date: Tue Feb  7 15:29:00 2012
New Revision: 1241488

URL: http://svn.apache.org/viewvc?rev=1241488&view=rev
Log:
o Moved the handling of the humanReadable flag in the LdapSyntax class
o Added the missing use cases handling in the BinaryAttributeDetector
o Added a flag in the LdapSyntax class to know if we have read the syntax from ADS/OpenLDAP or from any other server

Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/schema/DescriptionParsers.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/DefaultBinaryAttributeDectector.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/LdapSyntax.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/EntryUtils.java
    directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/shared/ldap/schemaloader/SchemaEntityFactory.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/schema/DescriptionParsers.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/schema/DescriptionParsers.java?rev=1241488&r1=1241487&r2=1241488&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/schema/DescriptionParsers.java (original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/schema/DescriptionParsers.java Tue Feb  7 15:29:00 2012
@@ -6,25 +6,22 @@
  *  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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server.core.api.schema;
 
 
 import java.text.ParseException;
-import java.util.List;
-
 import org.apache.directory.server.i18n.I18n;
-import org.apache.directory.shared.ldap.model.constants.MetaSchemaConstants;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.entry.Attribute;
 import org.apache.directory.shared.ldap.model.entry.Value;
@@ -211,11 +208,11 @@ public class DescriptionParsers
 
 
     /**
-     * Parses a set of attributeTypeDescriptions held within an attribute into 
+     * Parses a set of attributeTypeDescriptions held within an attribute into
      * schema entities.
      * 
      * @param attr the attribute containing attributeTypeDescriptions
-     * @return the set of attributeType objects for the descriptions 
+     * @return the set of attributeType objects for the descriptions
      * @throws LdapException if there are problems parsing the descriptions
      */
     public AttributeType[] parseAttributeTypes( Attribute attr ) throws LdapException
@@ -295,11 +292,11 @@ public class DescriptionParsers
 
 
     /**
-     * Parses a set of objectClassDescriptions held within an attribute into 
+     * Parses a set of objectClassDescriptions held within an attribute into
      * schema entities.
      * 
      * @param attr the attribute containing objectClassDescriptions
-     * @return the set of objectClass objects for the descriptions 
+     * @return the set of objectClass objects for the descriptions
      * @throws LdapException if there are problems parsing the descriptions
      */
     public ObjectClass[] parseObjectClasses( Attribute attr ) throws LdapException
@@ -385,11 +382,11 @@ public class DescriptionParsers
 
 
     /**
-     * Parses a set of matchingRuleUseDescriptions held within an attribute into 
+     * Parses a set of matchingRuleUseDescriptions held within an attribute into
      * schema entities.
      * 
      * @param attr the attribute containing matchingRuleUseDescriptions
-     * @return the set of matchingRuleUse objects for the descriptions 
+     * @return the set of matchingRuleUse objects for the descriptions
      * @throws org.apache.directory.shared.ldap.model.exception.LdapException if there are problems parsing the descriptions
      */
     public MatchingRuleUse[] parseMatchingRuleUses( Attribute attr ) throws LdapException
@@ -429,11 +426,11 @@ public class DescriptionParsers
 
 
     /**
-     * Parses a set of ldapSyntaxes held within an attribute into 
+     * Parses a set of ldapSyntaxes held within an attribute into
      * schema entities.
      * 
      * @param attr the attribute containing ldapSyntaxes
-     * @return the set of Syntax objects for the descriptions 
+     * @return the set of Syntax objects for the descriptions
      * @throws org.apache.directory.shared.ldap.model.exception.LdapException if there are problems parsing the descriptions
      */
     public LdapSyntax[] parseLdapSyntaxes( Attribute attr ) throws LdapException
@@ -470,7 +467,9 @@ public class DescriptionParsers
                 throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_423 ) );
             }
 
-            ldapSyntax.setHumanReadable( isHumanReadable( ldapSyntax ) );
+            // Call this method once to initialize the flags
+            ldapSyntax.isHumanReadable();
+            
             syntaxes[pos++] = ldapSyntax;
         }
 
@@ -479,11 +478,11 @@ public class DescriptionParsers
 
 
     /**
-     * Parses a set of matchingRuleDescriptions held within an attribute into 
+     * Parses a set of matchingRuleDescriptions held within an attribute into
      * schema entities.
      * 
      * @param attr the attribute containing matchingRuleDescriptions
-     * @return the set of matchingRule objects for the descriptions 
+     * @return the set of matchingRule objects for the descriptions
      * @throws LdapException if there are problems parsing the descriptions
      */
     public MatchingRule[] parseMatchingRules( Attribute attr ) throws LdapException
@@ -529,11 +528,11 @@ public class DescriptionParsers
 
 
     /**
-     * Parses a set of dITStructureRuleDescriptions held within an attribute into 
+     * Parses a set of dITStructureRuleDescriptions held within an attribute into
      * schema entities.
      * 
      * @param attr the attribute containing dITStructureRuleDescriptions
-     * @return the set of DITStructureRule objects for the descriptions 
+     * @return the set of DITStructureRule objects for the descriptions
      * @throws LdapException if there are problems parsing the descriptions
      */
     public DITStructureRule[] parseDitStructureRules( Attribute attr ) throws LdapException
@@ -573,11 +572,11 @@ public class DescriptionParsers
 
 
     /**
-     * Parses a set of dITContentRuleDescriptions held within an attribute into 
+     * Parses a set of dITContentRuleDescriptions held within an attribute into
      * schema entities.
      * 
      * @param attr the attribute containing dITContentRuleDescriptions
-     * @return the set of DITContentRule objects for the descriptions 
+     * @return the set of DITContentRule objects for the descriptions
      * @throws LdapException if there are problems parsing the descriptions
      */
     public DITContentRule[] parseDitContentRules( Attribute attr ) throws LdapException
@@ -617,11 +616,11 @@ public class DescriptionParsers
 
 
     /**
-     * Parses a set of nameFormDescriptions held within an attribute into 
+     * Parses a set of nameFormDescriptions held within an attribute into
      * schema entities.
      * 
      * @param attr the attribute containing nameFormDescriptions
-     * @return the set of NameFormRule objects for the descriptions 
+     * @return the set of NameFormRule objects for the descriptions
      * @throws LdapException if there are problems parsing the descriptions
      */
     public NameForm[] parseNameForms( Attribute attr ) throws LdapException
@@ -658,34 +657,4 @@ public class DescriptionParsers
 
         return nameForms;
     }
-
-
-    /**
-     * Checks to see if the syntax description is human readable by checking 
-     * for the presence of the X-IS-HUMAN_READABLE schema extension.
-     * 
-     * @param desc the ldapSyntax 
-     * @return true if the syntax is human readable, false otherwise
-     */
-    private boolean isHumanReadable( LdapSyntax ldapSyntax )
-    {
-        List<String> values = ldapSyntax.getExtensions().get( MetaSchemaConstants.X_NOT_HUMAN_READABLE );
-
-        if ( values == null || values.size() == 0 )
-        {
-            return false;
-        }
-        else
-        {
-            String value = values.get( 0 );
-            if ( value.equals( "TRUE" ) )
-            {
-                return true;
-            }
-            else
-            {
-                return false;
-            }
-        }
-    }
 }

Modified: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/DefaultBinaryAttributeDectector.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/DefaultBinaryAttributeDectector.java?rev=1241488&r1=1241487&r2=1241488&view=diff
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/DefaultBinaryAttributeDectector.java (original)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/DefaultBinaryAttributeDectector.java Tue Feb  7 15:29:00 2012
@@ -10,11 +10,22 @@ import org.apache.mina.util.ConcurrentHa
 
 public class DefaultBinaryAttributeDectector implements BinaryAttributeDetector
 {
+    /** A set of binary Attribute ID */
     private Set<String> binaryAttributes = new ConcurrentHashSet<String>();
+
+    /** A set of binary Syntax ID */
     private Set<String> binarySyntaxes = new ConcurrentHashSet<String>();
+    
+    /** The schemaManager to use */
     private SchemaManager schemaManager;
     
     
+    /**
+     * Creates a new instance of BinaryAttributeDetector. The SchemaManager can
+     * be null if we don't have any.
+     * 
+     * @param schemaManager The associated SchemaManager
+     */
     public DefaultBinaryAttributeDectector( SchemaManager schemaManager )
     {
         this.schemaManager = schemaManager;
@@ -46,29 +57,27 @@ public class DefaultBinaryAttributeDecte
             
             if ( ldapSyntax != null )
             {
-                if ( !ldapSyntax.isHumanReadable() )
+                if ( ldapSyntax.hasHumanReadableFlag() )
                 {
-                    return true;
+                    return !ldapSyntax.isHumanReadable();
                 }
                 else
                 {
+                    // Check the syntaxes
+                    String syntaxId = ldapSyntax.getOid();
                     
+                    return ( binarySyntaxes.contains( syntaxId ) );
                 }
-                
-                String syntaxId = ldapSyntax.getOid();
-                
-                return ( binarySyntaxes.contains( syntaxId ) );
             }
             else
             {
+                return binaryAttributes.contains( attrId );
             }
         }
         else
         {
             return binaryAttributes.contains( attrId );
         }
-        
-        return false;
     }
     
 

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/LdapSyntax.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/LdapSyntax.java?rev=1241488&r1=1241487&r2=1241488&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/LdapSyntax.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/LdapSyntax.java Tue Feb  7 15:29:00 2012
@@ -23,6 +23,7 @@ package org.apache.directory.shared.ldap
 import java.util.List;
 
 import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.model.constants.MetaSchemaConstants;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.schema.registries.Registries;
 import org.apache.directory.shared.ldap.model.schema.syntaxCheckers.OctetStringSyntaxChecker;
@@ -105,6 +106,7 @@ public class LdapSyntax extends Abstract
     {
         super( SchemaObjectType.LDAP_SYNTAX, oid );
         this.description = description;
+        this.hasHumanReadableFlag = false;
     }
 
 
@@ -120,6 +122,7 @@ public class LdapSyntax extends Abstract
         super( SchemaObjectType.LDAP_SYNTAX, oid );
         this.description = description;
         this.isHumanReadable = isHumanReadable;
+        this.hasHumanReadableFlag = true;
     }
 
 
@@ -130,7 +133,36 @@ public class LdapSyntax extends Abstract
      */
     public boolean isHumanReadable()
     {
-        return isHumanReadable;
+        if ( hasHumanReadableFlag )
+        {
+            return isHumanReadable;
+        }
+        else
+        {
+            List<String> values = extensions.get( MetaSchemaConstants.X_NOT_HUMAN_READABLE );
+
+            if ( ( values == null ) || ( values.size() == 0 ) )
+            {
+                // Default to String if the flag is not set
+                return false;
+            }
+            else
+            {
+                String value = values.get( 0 );
+                hasHumanReadableFlag = true;
+                
+                if ( value.equals( "FALSE" ) )
+                {
+                    isHumanReadable = true;
+                    return true;
+                }
+                else
+                {
+                    isHumanReadable = false;
+                    return false;
+                }
+            }
+        }
     }
 
 
@@ -154,6 +186,26 @@ public class LdapSyntax extends Abstract
 
 
     /**
+     * Gets whether or not the Human Readable extension is present in the Syntax.
+     * 
+     * @return true if the syntax contains teh X-NOT-HUMAN-READABLE extension
+     */
+    public boolean hasHumanReadableFlag()
+    {
+        return hasHumanReadableFlag;
+    }
+
+
+    /**
+     * Sets the hasHumanReadableFlag to true if we have a X-NOT-HUMAN-READABLE extension
+     */
+    public void setHasHumanReadableFlag()
+    {
+        hasHumanReadableFlag = true;
+    }
+
+
+    /**
      * Gets the SyntaxChecker used to validate values in accordance with this
      * Syntax.
      * 
@@ -272,6 +324,9 @@ public class LdapSyntax extends Abstract
         // Copy the HR flag
         copy.isHumanReadable = isHumanReadable;
 
+        // Copy the HR presence flag
+        copy.hasHumanReadableFlag = hasHumanReadableFlag;
+
         // All the references to other Registries object are set to null.
         copy.syntaxChecker = null;
 

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/EntryUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/EntryUtils.java?rev=1241488&r1=1241487&r2=1241488&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/EntryUtils.java (original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/EntryUtils.java Tue Feb  7 15:29:00 2012
@@ -6,16 +6,16 @@
  *  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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.shared.ldap.model.entry;
 
@@ -89,9 +89,9 @@ public class EntryUtils
 
     static class S extends LdapSyntax
     {
-        public S( String oid, boolean humanReadible )
+        public S( String oid, boolean humanReadable )
         {
-            super( oid, "", humanReadible );
+            super( oid, "", humanReadable );
         }
     }
 

Modified: directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/shared/ldap/schemaloader/SchemaEntityFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/shared/ldap/schemaloader/SchemaEntityFactory.java?rev=1241488&r1=1241487&r2=1241488&view=diff
==============================================================================
--- directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/shared/ldap/schemaloader/SchemaEntityFactory.java (original)
+++ directory/shared/trunk/ldap/schema/data/src/main/java/org/apache/directory/shared/ldap/schemaloader/SchemaEntityFactory.java Tue Feb  7 15:29:00 2012
@@ -710,6 +710,7 @@ public class SchemaEntityFactory impleme
         {
             String val = mHumanReadable.getString();
             syntax.setHumanReadable( val.toUpperCase().equals( "FALSE" ) );
+            syntax.setHasHumanReadableFlag();
         }
 
         // Common properties