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 2010/01/06 18:52:31 UTC

svn commit: r896579 [5/14] - in /directory/shared/trunk: ./ ldap/ ldap/src/main/antlr/ ldap/src/main/java/org/apache/directory/shared/ldap/ ldap/src/main/java/org/apache/directory/shared/ldap/codec/ ldap/src/main/java/org/apache/directory/shared/ldap/c...

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DescriptionUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DescriptionUtils.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DescriptionUtils.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/DescriptionUtils.java Wed Jan  6 17:52:15 2010
@@ -20,24 +20,27 @@
 package org.apache.directory.shared.ldap.schema;
 
 
-import javax.naming.NamingException;
+import java.util.List;
+import java.util.Map;
 
 
 /**
  * Utility class used to generate schema object specifications. Some of the
  * latest work coming out of the LDAPBIS working body adds optional extensions
- * to these syntaxes. We have not yet added extension support to these functions
- * or the schema interfaces in this package. Descriptions can be generated for
+ * to these syntaxes. Descriptions can be generated for
  * the following objects:
  * <ul>
  * <li><a href="./AttributeType.html">AttributeType</a></li>
  * <li><a href="./DITContentRule.html">DITContentRule</a></li>
+ * <li><a href="./DITContentRule.html">DITStructureRule</a></li>
+ * <li><a href="./LdapComparator.html">Syntax</a></li>
  * <li><a href="./MatchingRule.html">MatchingRule</a></li>
  * <li><a href="./MatchingRuleUse.html">MatchingRuleUse</a></li>
  * <li><a href="./NameForm.html">NameForm</a></li>
+ * <li><a href="./Normalizer.html">Syntax</a></li>
  * <li><a href="./ObjectClass.html">ObjectClass</a></li>
- * <li><a href="./DITStructureRule.html">DITStructureRule</a></li>
- * <li><a href="./Syntax.html">Syntax</a></li>
+ * <li><a href="./LdapSyntax.html">Syntax</a></li>
+ * <li><a href="./SyntaxChecker.html">Syntax</a></li>
  * </ul>
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
@@ -48,7 +51,7 @@
     /**
      * Generates the description using the AttributeTypeDescription as defined
      * by the syntax: 1.3.6.1.4.1.1466.115.121.1.3. Only the right hand side of
-     * the description starting at the openning parenthesis is generated: that
+     * the description starting at the opening parenthesis is generated: that
      * is 'AttributeTypeDescription = ' is not generated.
      * 
      * <pre>
@@ -73,89 +76,132 @@
      *            the attributeType to generate a description for
      * @return the AttributeTypeDescription Syntax for the attributeType in a
      *         pretty formated string
-     * @throws NamingException If an error is raised while accessing some of the attributeType
-     * data 
      */
-    public static String getDescription( AttributeType attributeType ) throws NamingException
+    public static String getDescription( AttributeType attributeType )
     {
-        StringBuffer buf = new StringBuffer( "( " );
+        StringBuilder buf = new StringBuilder( "( " );
         buf.append( attributeType.getOid() );
         buf.append( '\n' );
 
-        buf.append( "NAME " );
-        buf.append( attributeType.getName() );
-        buf.append( '\n' );
+        if ( attributeType.getNames().size() != 0 )
+        {
+            buf.append( " NAME " );
+            getQDescrs( buf, attributeType.getNames() );
+        }
 
         if ( attributeType.getDescription() != null )
         {
-            buf.append( "DESC " );
+            buf.append( " DESC " );
             buf.append( attributeType.getDescription() );
             buf.append( '\n' );
         }
 
         if ( attributeType.isObsolete() )
         {
-            buf.append( "OBSOLETE" );
-            buf.append( '\n' );
+            buf.append( " OBSOLETE\n" );
         }
 
-        buf.append( attributeType.getSuperior().getOid() );
+        if ( attributeType.getSuperior() != null )
+        {
+            buf.append( " SUP " );
+            buf.append( attributeType.getSuperiorName() );
+            buf.append( '\n' );
+        }
 
         if ( attributeType.getEquality() != null )
         {
-            buf.append( "EQUALITY " );
-            buf.append( attributeType.getEquality().getOid() );
+            buf.append( " EQUALITY " );
+            buf.append( attributeType.getEqualityName() );
             buf.append( '\n' );
         }
 
         if ( attributeType.getOrdering() != null )
         {
-            buf.append( "ORDERING " );
-            buf.append( attributeType.getOrdering().getOid() );
+            buf.append( " ORDERING " );
+            buf.append( attributeType.getOrderingName() );
             buf.append( '\n' );
         }
 
-        if ( attributeType.getSubstr() != null )
+        if ( attributeType.getSubstring() != null )
         {
-            buf.append( "SUBSTR " );
-            buf.append( attributeType.getSubstr().getOid() );
+            buf.append( " SUBSTR " );
+            buf.append( attributeType.getSubstringName() );
             buf.append( '\n' );
         }
 
-        buf.append( "SYNTAX " );
-        buf.append( attributeType.getSyntax().getOid() );
-        buf.append( '\n' );
-
-        if ( attributeType.isSingleValue() )
+        if ( attributeType.getSyntax() != null )
         {
-            buf.append( "SINGLE-VALUE" );
+            buf.append( " SYNTAX " );
+
+            buf.append( attributeType.getSyntaxName() );
+
+            if ( attributeType.getSyntaxLength() > 0 )
+            {
+                buf.append( '{' ).append( attributeType.getSyntaxLength() ).append( '}' );
+            }
+
             buf.append( '\n' );
         }
 
+        if ( attributeType.isSingleValued() )
+        {
+            buf.append( " SINGLE-VALUE\n" );
+        }
+
         if ( attributeType.isCollective() )
         {
-            buf.append( "COLLECTIVE" );
-            buf.append( '\n' );
+            buf.append( " COLLECTIVE\n" );
         }
 
-        if ( attributeType.isCanUserModify() )
+        if ( !attributeType.isUserModifiable() )
         {
-            buf.append( "NO-USER-MODIFICATION" );
-            buf.append( '\n' );
+            buf.append( " NO-USER-MODIFICATION\n" );
         }
 
-        buf.append( "USAGE " );
+        buf.append( " USAGE " );
         buf.append( UsageEnum.render( attributeType.getUsage() ) );
-        buf.append( " ) " );
+        buf.append( '\n' );
+
+        if ( attributeType.getExtensions() != null )
+        {
+            getExtensions( buf, attributeType.getExtensions() );
+        }
+
+        buf.append( " )\n" );
 
         return buf.toString();
     }
 
 
     /**
+     * Generates the ComparatorDescription for a LdapComparator. Only the right 
+     * hand side of the description starting at the opening parenthesis is 
+     * generated: that is 'ComparatorDescription = ' is not generated.
+     * 
+     * <pre>
+     * ComparatorDescription = &quot;(&quot;
+     *     numericoid                          
+     *     [&quot;DESC&quot; qdstring ]
+     *     &quot;FQCN&quot; whsp fqcn
+     *     [&quot;BYTECODE&quot; whsp base64  ]
+     *     extensions 
+     *     &quot;)&quot;
+     * </pre>
+     * 
+     * @param comparator
+     *            the Comparator to generate the description for
+     * @return the ComparatorDescription string
+     */
+    public static String getDescription( LdapComparator<?> comparator )
+    {
+        return getLoadableDescription( comparator );
+    }
+
+
+    /**
      * Generates the DITContentRuleDescription for a DITContentRule as defined
      * by the syntax: 1.3.6.1.4.1.1466.115.121.1.16. Only the right hand side of
-     * the description starting at the openning parenthesis is generated: that
+     * the description starting at the opening parenthesis is generated: that
      * is 'DITContentRuleDescription = ' is not generated.
      * 
      * <pre>
@@ -175,90 +221,163 @@
      *            the DIT content rule specification
      * @return the specification according to the DITContentRuleDescription
      *         syntax
-     * @throws NamingException If an error is raised while accessing some of the dITConentRule
-     * data 
      */
-    public static String getDescription( DITContentRule dITContentRule ) throws NamingException
+    public static String getDescription( DITContentRule dITContentRule )
     {
-        StringBuffer buf = new StringBuffer( "( " );
+        StringBuilder buf = new StringBuilder( "( " );
         buf.append( dITContentRule.getOid() );
         buf.append( '\n' );
 
-        buf.append( "NAME " );
-        buf.append( dITContentRule.getName() );
-        buf.append( '\n' );
+        if ( dITContentRule.getNames() != null )
+        {
+            buf.append( " NAME " );
+            getQDescrs( buf, dITContentRule.getNames() );
+            buf.append( '\n' );
+        }
 
         if ( dITContentRule.getDescription() != null )
         {
-            buf.append( "DESC " );
+            buf.append( " DESC " );
             buf.append( dITContentRule.getDescription() );
             buf.append( '\n' );
         }
 
         if ( dITContentRule.isObsolete() )
         {
-            buf.append( "OBSOLETE" );
-            buf.append( '\n' );
+            buf.append( " OBSOLETE\n" );
         }
 
         // print out all the auxiliary object class oids
-        ObjectClass[] aux = dITContentRule.getAuxObjectClasses();
-        
-        if ( aux != null && aux.length > 0 )
+        List<ObjectClass> aux = dITContentRule.getAuxObjectClasses();
+
+        if ( ( aux != null ) && ( aux.size() > 0 ) )
         {
-            buf.append( "AUX\n" );
-            
-            for ( ObjectClass objectClass: aux )
-            {
-                buf.append( '\t' );
-                buf.append( objectClass.getOid() );
-                buf.append( '\n' );
-            }
+            buf.append( " AUX " );
+            getQDStrings( buf, aux );
         }
 
-        AttributeType[] must = dITContentRule.getMustNames();
-        
-        if ( must != null && must.length > 0 )
+        List<AttributeType> must = dITContentRule.getMustAttributeTypes();
+
+        if ( ( must != null ) && ( must.size() > 0 ) )
         {
-            buf.append( "MUST\n" );
-            
-            for ( AttributeType attributeType:must )
-            {
-                buf.append( '\t' );
-                buf.append( attributeType.getOid() );
-                buf.append( '\n' );
-            }
+            buf.append( " MUST " );
+            getQDStrings( buf, must );
         }
 
-        AttributeType[] may = dITContentRule.getMayNames();
-        
-        if ( may != null && may.length > 0 )
+        List<AttributeType> may = dITContentRule.getMayAttributeTypes();
+
+        if ( ( may != null ) && ( may.size() > 0 ) )
         {
-            buf.append( "MAY\n" );
-            
-            for ( AttributeType attributeType:may )
-            {
-                buf.append( '\t' );
-                buf.append( attributeType.getOid() );
-                buf.append( '\n' );
-            }
+            buf.append( " MAY " );
+            getQDStrings( buf, may );
+        }
+
+        List<AttributeType> not = dITContentRule.getNotAttributeTypes();
+
+        if ( ( not != null ) && ( not.size() > 0 ) )
+        {
+            buf.append( " NOT " );
+            getQDStrings( buf, not );
         }
 
-        AttributeType[] not = dITContentRule.getNotNames();
-        
-        if ( not != null && not.length > 0 )
+        if ( dITContentRule.getExtensions() != null )
         {
-            buf.append( "NOT\n" );
-            
-            for ( AttributeType attributeType:not )
+            getExtensions( buf, dITContentRule.getExtensions() );
+        }
+
+        buf.append( " )\n" );
+        return buf.toString();
+    }
+
+
+    /**
+     * Generates the DITStructureRuleDescription for a DITStructureRule as
+     * defined by the syntax: 1.3.6.1.4.1.1466.115.121.1.17. Only the right hand
+     * side of the description starting at the opening parenthesis is
+     * generated: that is 'DITStructureRuleDescription = ' is not generated.
+     * 
+     * <pre>
+     *   DITStructureRuleDescription = &quot;(&quot; whsp
+     *       ruleid                     ; rule identifier
+     *       [ SP "NAME" SP qdescrs ]   ; short names (descriptors)
+     *       [ SP "DESC" SP qdstring ]  ; description
+     *       [ SP "OBSOLETE" ]          ; not active
+     *       SP "FORM" SP oid           ; NameForm
+     *       [ SP "SUP" ruleids ]       ; superior rules
+     *       extensions WSP             ; extensions
+     *       &quot;)&quot;
+     * </pre>
+     * 
+     * @param dITStructureRule
+     *            the DITStructureRule to generate the description for
+     * @return the description in the DITStructureRuleDescription syntax
+     */
+    public static String getDescription( DITStructureRule dITStructureRule )
+    {
+        StringBuilder buf = new StringBuilder( "( " );
+        buf.append( dITStructureRule.getOid() );
+        buf.append( '\n' );
+
+        if ( dITStructureRule.getNames() != null )
+        {
+            buf.append( " NAME " );
+            getQDescrs( buf, dITStructureRule.getNames() );
+        }
+
+        if ( dITStructureRule.getDescription() != null )
+        {
+            buf.append( " DESC " );
+            buf.append( dITStructureRule.getDescription() );
+            buf.append( '\n' );
+        }
+
+        if ( dITStructureRule.isObsolete() )
+        {
+            buf.append( " OBSOLETE\n" );
+        }
+
+        buf.append( " FORM " );
+        buf.append( dITStructureRule.getForm() );
+        buf.append( '\n' );
+
+        // TODO : Shouldn't we get the ruleId OID ? 
+        List<Integer> sups = dITStructureRule.getSuperRules();
+
+        if ( ( sups != null ) && ( sups.size() > 0 ) )
+        {
+            buf.append( " SUP\n" );
+
+            if ( sups.size() == 1 )
             {
-                buf.append( '\t' );
-                buf.append( attributeType.getOid() );
-                buf.append( '\n' );
+                buf.append( sups.get( 0 ) );
             }
+            else
+            {
+                boolean isFirst = true;
+                buf.append( "( " );
+
+                for ( int sup : sups )
+                {
+                    if ( isFirst )
+                    {
+                        isFirst = false;
+                    }
+                    else
+                    {
+                        buf.append( " " );
+                    }
+
+                    buf.append( sup );
+                }
+
+                buf.append( " )" );
+            }
+
+            buf.append( '\n' );
         }
 
-        buf.append( " )" );
+        buf.append( " )\n" );
+
         return buf.toString();
     }
 
@@ -266,7 +385,7 @@
     /**
      * Generates the MatchingRuleDescription for a MatchingRule as defined by
      * the syntax: 1.3.6.1.4.1.1466.115.121.1.30. Only the right hand side of
-     * the description starting at the openning parenthesis is generated: that
+     * the description starting at the opening parenthesis is generated: that
      * is 'MatchingRuleDescription = ' is not generated.
      * 
      * <pre>
@@ -282,34 +401,40 @@
      * @param matchingRule
      *            the MatchingRule to generate the description for
      * @return the MatchingRuleDescription string
-     * @throws NamingException If an error is raised while accessing some of the matchingRule
-     * data 
      */
-    public static String getDescription( MatchingRule matchingRule ) throws NamingException
+    public static String getDescription( MatchingRule matchingRule )
     {
-        StringBuffer buf = new StringBuffer( "( " );
+        StringBuilder buf = new StringBuilder( "( " );
         buf.append( matchingRule.getOid() );
         buf.append( '\n' );
 
-        buf.append( "NAME " );
-        buf.append( matchingRule.getName() );
-        buf.append( '\n' );
+        if ( matchingRule.getNames() != null )
+        {
+            buf.append( " NAME " );
+            getQDescrs( buf, matchingRule.getNames() );
+        }
 
         if ( matchingRule.getDescription() != null )
         {
-            buf.append( "DESC " );
+            buf.append( " DESC " );
             buf.append( matchingRule.getDescription() );
             buf.append( '\n' );
         }
 
         if ( matchingRule.isObsolete() )
         {
-            buf.append( "OBSOLETE" );
-            buf.append( '\n' );
+            buf.append( " OBSOLETE\n" );
+        }
+
+        buf.append( " SYNTAX " );
+        buf.append( matchingRule.getSyntaxOid() );
+        buf.append( '\n' );
+
+        if ( matchingRule.getExtensions() != null )
+        {
+            getExtensions( buf, matchingRule.getExtensions() );
         }
 
-        buf.append( "SYNTAX " );
-        buf.append( matchingRule.getSyntax().getOid() );
         buf.append( " ) " );
         return buf.toString();
     }
@@ -318,7 +443,7 @@
     /**
      * Generates the MatchingRuleUseDescription for a MatchingRuleUse as defined
      * by the syntax: 1.3.6.1.4.1.1466.115.121.1.31. Only the right hand side of
-     * the description starting at the openning parenthesis is generated: that
+     * the description starting at the opening parenthesis is generated: that
      * is 'MatchingRuleUseDescription = ' is not generated.
      * 
      * <pre>
@@ -345,52 +470,66 @@
      * @param matchingRuleUse The matching rule from which we want to generate
      *  a MatchingRuleUseDescription.
      * @return The generated MatchingRuleUseDescription
-     * @throws NamingException If an error is raised while accessing some of the matchingRuleUse
-     * data 
      */
-    public static String getDescription( MatchingRuleUse matchingRuleUse ) throws NamingException
+    public static String getDescription( MatchingRuleUse matchingRuleUse )
     {
-        StringBuffer buf = new StringBuffer( "( " );
-        buf.append( matchingRuleUse.getMatchingRule().getOid() );
+        StringBuilder buf = new StringBuilder( "( " );
+        buf.append( matchingRuleUse.getOid() );
         buf.append( '\n' );
 
-        buf.append( "NAME " );
-        buf.append( matchingRuleUse.getName() );
-        buf.append( '\n' );
+        buf.append( " NAME " );
+        getQDescrs( buf, matchingRuleUse.getNames() );
 
         if ( matchingRuleUse.getDescription() != null )
         {
-            buf.append( "DESC " );
+            buf.append( " DESC " );
             buf.append( matchingRuleUse.getDescription() );
             buf.append( '\n' );
         }
 
         if ( matchingRuleUse.isObsolete() )
         {
-            buf.append( "OBSOLETE" );
-            buf.append( '\n' );
+            buf.append( " OBSOLETE\n" );
         }
 
-        buf.append( "APPLIES " );
-        AttributeType[] attributeTypes = matchingRuleUse.getApplicableAttributes();
-        if ( attributeTypes.length == 1 )
+        buf.append( " APPLIES " );
+        List<AttributeType> attributeTypes = matchingRuleUse.getApplicableAttributes();
+
+        if ( attributeTypes.size() == 1 )
         {
-            buf.append( attributeTypes[0].getOid() );
+            buf.append( attributeTypes.get( 0 ).getOid() );
         }
         else
         // for list of oids we need a parenthesis
         {
             buf.append( "( " );
-            buf.append( attributeTypes[0] );
-            for ( int ii = 1; ii < attributeTypes.length; ii++ )
+
+            boolean isFirst = true;
+
+            for ( AttributeType attributeType : attributeTypes )
             {
-                buf.append( " $ " );
-                buf.append( attributeTypes[ii] );
+                if ( isFirst )
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    buf.append( " $ " );
+                }
+
+                buf.append( attributeType );
             }
+
             buf.append( " ) " );
         }
 
-        buf.append( '\n' );
+        if ( matchingRuleUse.getExtensions() != null )
+        {
+            getExtensions( buf, matchingRuleUse.getExtensions() );
+        }
+
+        buf.append( " )\n" );
+
         return buf.toString();
     }
 
@@ -398,7 +537,7 @@
     /**
      * Generates the NameFormDescription for a NameForm as defined by the
      * syntax: 1.3.6.1.4.1.1466.115.121.1.35. Only the right hand side of the
-     * description starting at the openning parenthesis is generated: that is
+     * description starting at the opening parenthesis is generated: that is
      * 'NameFormDescription = ' is not generated.
      * 
      * <pre>
@@ -416,69 +555,87 @@
      * @param nameForm
      *            the NameForm to generate the description for
      * @return the NameFormDescription string
-     * @throws NamingException If an error is raised while accessing some of the nameForm
-     * data 
      */
-    public static String getDescription( NameForm nameForm ) throws NamingException
+    public static String getDescription( NameForm nameForm )
     {
-        StringBuffer buf = new StringBuffer( "( " );
+        StringBuilder buf = new StringBuilder( "( " );
         buf.append( nameForm.getOid() );
         buf.append( '\n' );
 
-        buf.append( "NAME " );
-        buf.append( nameForm.getName() );
-        buf.append( '\n' );
+        if ( nameForm.getNames() != null )
+        {
+            buf.append( " NAME " );
+            getQDescrs( buf, nameForm.getNames() );
+        }
 
         if ( nameForm.getDescription() != null )
         {
-            buf.append( "DESC " );
+            buf.append( " DESC " );
             buf.append( nameForm.getDescription() );
             buf.append( '\n' );
         }
 
         if ( nameForm.isObsolete() )
         {
-            buf.append( "OBSOLETE" );
-            buf.append( '\n' );
+            buf.append( " OBSOLETE\n" );
         }
 
-        buf.append( "OC " );
-        buf.append( nameForm.getObjectClass().getOid() );
+        buf.append( " OC " );
+        buf.append( nameForm.getStructuralObjectClassOid() );
         buf.append( '\n' );
 
-        buf.append( "MUST\n" );
-        AttributeType[] must = nameForm.getMustUse();
-        
-        for ( AttributeType attributeType:must )
+        buf.append( " MUST\n" );
+        List<AttributeType> must = nameForm.getMustAttributeTypes();
+
+        getQDStrings( buf, must );
+
+        List<AttributeType> may = nameForm.getMayAttributeTypes();
+
+        if ( ( may != null ) && ( may.size() > 0 ) )
         {
-            buf.append( '\t' );
-            buf.append( attributeType.getOid() );
-            buf.append( '\n' );
+            buf.append( " MAY\n" );
+            getQDStrings( buf, may );
         }
 
-        AttributeType[] may = nameForm.getMayUse();
-
-        if ( may != null && may.length > 0 )
+        if ( nameForm.getExtensions() != null )
         {
-            buf.append( "MAY\n" );
-        
-            for ( AttributeType attributeType:may )
-            {
-                buf.append( '\t' );
-                buf.append( attributeType.getOid() );
-                buf.append( '\n' );
-            }
+            getExtensions( buf, nameForm.getExtensions() );
         }
 
-        buf.append( " )" );
+        buf.append( " )\n" );
         return buf.toString();
     }
 
 
     /**
+     * Generates the NormalizerDescription for a Normalizer. Only the right 
+     * hand side of the description starting at the opening parenthesis is 
+     * generated: that is 'NormalizerDescription = ' is not generated.
+     * 
+     * <pre>
+     * NormalizerDescription = &quot;(&quot;
+     *     numericoid                          
+     *     [&quot;DESC&quot; qdstring ]
+     *     &quot;FQCN&quot; whsp fqcn
+     *     [&quot;BYTECODE&quot; whsp base64  ]
+     *     extensions 
+     *     &quot;)&quot;
+     * </pre>
+     * 
+     * @param normalizer
+     *            the Normalizer to generate the description for
+     * @return the NormalizerDescription string
+     */
+    public static String getDescription( Normalizer normalizer )
+    {
+        return getLoadableDescription( normalizer );
+    }
+
+
+    /**
      * Generates the ObjectClassDescription for an ObjectClass as defined by the
      * syntax: 1.3.6.1.4.1.1466.115.121.1.37. Only the right hand side of the
-     * description starting at the openning parenthesis is generated: that is
+     * description starting at the opening parenthesis is generated: that is
      * 'ObjectClassDescription = ' is not generated.
      * 
      * <pre>
@@ -498,145 +655,107 @@
      * @param objectClass
      *            the ObjectClass to generate a description for
      * @return the description in the ObjectClassDescription syntax
-     * @throws NamingException If an error is raised while accessing some of the objectClass
-     * data 
      */
-    public static String getDescription( ObjectClass objectClass ) throws NamingException
+    public static String getDescription( ObjectClass objectClass )
     {
-        StringBuffer buf = new StringBuffer( "( " );
+        StringBuilder buf = new StringBuilder( "( " );
         buf.append( objectClass.getOid() );
         buf.append( '\n' );
 
-        buf.append( "NAME " );
-        buf.append( objectClass.getName() );
-        buf.append( '\n' );
+        if ( ( objectClass.getNames() != null ) && ( objectClass.getNames().size() != 0 ) )
+        {
+            buf.append( " NAME " );
+            getQDescrs( buf, objectClass.getNames() );
+        }
 
         if ( objectClass.getDescription() != null )
         {
-            buf.append( "DESC " );
+            buf.append( " DESC " );
             buf.append( objectClass.getDescription() );
             buf.append( '\n' );
         }
 
         if ( objectClass.isObsolete() )
         {
-            buf.append( "OBSOLETE" );
-            buf.append( '\n' );
+            buf.append( " OBSOLETE\n" );
         }
 
-        ObjectClass[] sups = objectClass.getSuperClasses();
+        List<ObjectClass> sups = objectClass.getSuperiors();
 
-        if ( sups != null && sups.length > 0 )
+        if ( ( sups != null ) && ( sups.size() > 0 ) )
         {
-            buf.append( "SUP\n" );
-            
-            for ( ObjectClass sup:sups )
-            {
-                buf.append( '\t' );
-                buf.append( sup.getOid() );
-                buf.append( '\n' );
-            }
+            buf.append( " SUP " );
+            getQDStrings( buf, sups );
         }
 
         if ( objectClass.getType() != null )
         {
+            buf.append( ' ' );
             buf.append( objectClass.getType() );
             buf.append( '\n' );
         }
 
-        AttributeType[] must = objectClass.getMustList();
-        if ( must != null && must.length > 0 )
+        List<AttributeType> must = objectClass.getMustAttributeTypes();
+
+        if ( ( must != null ) && ( must.size() > 0 ) )
         {
-            buf.append( "MUST\n" );
-            
-            for ( AttributeType attributeType:must )
-            {
-                buf.append( '\t' );
-                buf.append( attributeType.getOid() );
-                buf.append( '\n' );
-            }
+            buf.append( " MUST " );
+            getQDStrings( buf, must );
         }
 
-        AttributeType[] may = objectClass.getMayList();
-        
-        if ( may != null && may.length > 0 )
+        List<AttributeType> may = objectClass.getMayAttributeTypes();
+
+        if ( ( may != null ) && ( may.size() > 0 ) )
         {
-            buf.append( "MAY\n" );
+            buf.append( " MAY " );
+            getQDStrings( buf, may );
+        }
 
-            for ( AttributeType attributeType:may )
-            {
-                buf.append( '\t' );
-                buf.append( attributeType.getOid() );
-                buf.append( '\n' );
-            }
+        if ( objectClass.getExtensions() != null )
+        {
+            getExtensions( buf, objectClass.getExtensions() );
         }
 
-        buf.append( " )" );
+        buf.append( " )\n" );
+
         return buf.toString();
     }
 
 
     /**
-     * Generates the DITStructureRuleDescription for a DITStructureRule as
-     * defined by the syntax: 1.3.6.1.4.1.1466.115.121.1.17. Only the right hand
-     * side of the description starting at the openning parenthesis is
-     * generated: that is 'DITStructureRuleDescription = ' is not generated.
+     * Generates the SyntaxDescription for a Syntax as defined by the syntax:
+     * 1.3.6.1.4.1.1466.115.121.1.54. Only the right hand side of the
+     * description starting at the opening parenthesis is generated: that is
+     * 'SyntaxDescription = ' is not generated.
      * 
      * <pre>
-     *  DITStructureRuleDescription = &quot;(&quot; whsp
-     *      ruleidentifier whsp           ; DITStructureRule identifier
-     *      [ &quot;NAME&quot; qdescrs ]
+     *  SyntaxDescription = &quot;(&quot; whsp
+     *      numericoid whsp
      *      [ &quot;DESC&quot; qdstring ]
-     *      [ &quot;OBSOLETE&quot; whsp ]
-     *      &quot;FORM&quot; woid whsp              ; NameForm
-     *      [ &quot;SUP&quot; ruleidentifiers whsp ]; superior DITStructureRules
-     *  &quot;)&quot;
+     *      [ extensions ]
+     *      whsp &quot;)&quot;
      * </pre>
      * 
-     * @param dITStructureRule
-     *            the DITStructureRule to generate the description for
-     * @return the description in the DITStructureRuleDescription syntax
-     * @throws NamingException If an error is raised while accessing some of the dITStructureRule
-     * data 
+     * @param syntax
+     *            the Syntax to generate a description for
+     * @return the description in the SyntaxDescription syntax
      */
-    public static String getDescription( DITStructureRule dITStructureRule ) throws NamingException
+    public static String getDescription( LdapSyntax syntax )
     {
-        StringBuffer buf = new StringBuffer( "( " );
-        buf.append( dITStructureRule.getOid() );
-        buf.append( '\n' );
-
-        buf.append( "NAME " );
-        buf.append( dITStructureRule.getName() );
+        StringBuilder buf = new StringBuilder( "( " );
+        buf.append( syntax.getOid() );
         buf.append( '\n' );
 
-        if ( dITStructureRule.getDescription() != null )
-        {
-            buf.append( "DESC " );
-            buf.append( dITStructureRule.getDescription() );
-            buf.append( '\n' );
-        }
-
-        if ( dITStructureRule.isObsolete() )
+        if ( syntax.getDescription() != null )
         {
-            buf.append( "OBSOLETE" );
+            buf.append( " DESC " );
+            buf.append( syntax.getDescription() );
             buf.append( '\n' );
         }
 
-        buf.append( "FORM " );
-        buf.append( dITStructureRule.getNameForm().getOid() );
-        buf.append( '\n' );
-
-        DITStructureRule[] sups = dITStructureRule.getSuperClasses();
-        if ( sups != null && sups.length > 0 )
+        if ( syntax.getExtensions() != null )
         {
-            buf.append( "SUP\n" );
-            
-            for ( DITStructureRule sup:sups )
-            {
-                buf.append( '\t' );
-                buf.append( sup.getOid() );
-                buf.append( '\n' );
-            }
+            getExtensions( buf, syntax.getExtensions() );
         }
 
         buf.append( " )" );
@@ -645,36 +764,189 @@
 
 
     /**
-     * Generates the SyntaxDescription for a Syntax as defined by the syntax:
-     * 1.3.6.1.4.1.1466.115.121.1.54. Only the right hand side of the
-     * description starting at the openning parenthesis is generated: that is
-     * 'SyntaxDescription = ' is not generated.
+     * Generates the SyntaxCheckerDescription for a SyntaxChecker. Only the right 
+     * hand side of the description starting at the opening parenthesis is 
+     * generated: that is 'SyntaxCheckerDescription = ' is not generated.
      * 
      * <pre>
-     *  SyntaxDescription = &quot;(&quot; whsp
-     *      numericoid whsp
-     *      [ &quot;DESC&quot; qdstring ]
-     *  whsp &quot;)&quot;
+     * SyntaxCheckerDescription = &quot;(&quot;
+     *     numericoid                          
+     *     [&quot;DESC&quot; qdstring ]
+     *     &quot;FQCN&quot; whsp fqcn
+     *     [&quot;BYTECODE&quot; whsp base64  ]
+     *     extensions 
+     *     &quot;)&quot;
      * </pre>
      * 
-     * @param syntax
-     *            the Syntax to generate a description for
-     * @return the description in the SyntaxDescription syntax
+     * @param syntaxChecker
+     *            the SyntaxChecker to generate the description for
+     * @return the SyntaxCheckerDescription string
      */
-    public static String getDescription( Syntax syntax )
+    public static String getDescription( SyntaxChecker syntaxChecker )
     {
-        StringBuffer buf = new StringBuffer( "( " );
-        buf.append( syntax.getOid() );
+        return getLoadableDescription( syntaxChecker );
+    }
+
+
+    private static void getExtensions( StringBuilder sb, Map<String, List<String>> extensions )
+    {
+        for ( String key : extensions.keySet() )
+        {
+            sb.append( key ).append( " " );
+
+            List<String> values = extensions.get( key );
+
+            if ( ( values != null ) && ( values.size() != 0 ) )
+            {
+                if ( values.size() == 1 )
+                {
+                    sb.append( values.get( 0 ) );
+                }
+                else
+                {
+                    boolean isFirst = true;
+                    sb.append( "( " );
+
+                    for ( String value : values )
+                    {
+                        if ( isFirst )
+                        {
+                            isFirst = false;
+                        }
+                        else
+                        {
+                            sb.append( " " );
+                        }
+
+                        sb.append( value );
+                    }
+
+                    sb.append( " )" );
+                }
+            }
+
+            sb.append( '\n' );
+        }
+    }
+
+
+    private static void getQDStrings( StringBuilder sb, List<? extends SchemaObject> schemaObjects )
+    {
+        if ( ( schemaObjects != null ) && ( schemaObjects.size() != 0 ) )
+        {
+            if ( schemaObjects.size() == 1 )
+            {
+                sb.append( '\'' ).append( schemaObjects.get( 0 ).getName() ).append( '\'' );
+            }
+            else
+            {
+                boolean isFirst = true;
+                sb.append( "( " );
+
+                for ( SchemaObject schemaObject : schemaObjects )
+                {
+                    if ( isFirst )
+                    {
+                        isFirst = false;
+                    }
+                    else
+                    {
+                        sb.append( " " );
+                    }
+
+                    sb.append( '\'' ).append( schemaObject.getName() ).append( '\'' );
+                }
+
+                sb.append( " )" );
+            }
+        }
+
+        sb.append( '\n' );
+    }
+
+
+    private static void getQDescrs( StringBuilder sb, List<String> names )
+    {
+        if ( ( names != null ) && ( names.size() != 0 ) )
+        {
+            if ( names.size() == 1 )
+            {
+                sb.append( '\'' ).append( names.get( 0 ) ).append( '\'' );
+            }
+            else
+            {
+                boolean isFirst = true;
+                sb.append( "( " );
+
+                for ( String name : names )
+                {
+                    if ( isFirst )
+                    {
+                        isFirst = false;
+                    }
+                    else
+                    {
+                        sb.append( " " );
+                    }
+
+                    sb.append( '\'' ).append( name ).append( '\'' );
+                }
+
+                sb.append( " )" );
+            }
+        }
+
+        sb.append( '\n' );
+    }
+
+
+    /**
+     * Generate the description for Comparators, Normalizers and SyntaxCheckers.
+     */
+    private static String getLoadableDescription( LoadableSchemaObject schemaObject )
+    {
+        StringBuilder buf = new StringBuilder( "( " );
+        buf.append( schemaObject.getOid() );
         buf.append( '\n' );
 
-        if ( syntax.getDescription() != null )
+        if ( schemaObject.getDescription() != null )
         {
-            buf.append( "DESC " );
-            buf.append( syntax.getDescription() );
+            buf.append( " DESC " );
+            buf.append( schemaObject.getDescription() );
             buf.append( '\n' );
         }
 
-        buf.append( " )" );
+        if ( schemaObject.getFqcn() != null )
+        {
+            buf.append( " FQCN " );
+            buf.append( schemaObject.getFqcn() );
+            buf.append( '\n' );
+        }
+
+        if ( schemaObject.getBytecode() != null )
+        {
+            buf.append( " BYTECODE " );
+
+            // We will dump only the 16 first bytes
+            if ( schemaObject.getBytecode().length() > 16 )
+            {
+                buf.append( schemaObject.getBytecode().substring( 0, 16 ) );
+            }
+            else
+            {
+                buf.append( schemaObject.getBytecode() );
+            }
+
+            buf.append( '\n' );
+        }
+
+        if ( schemaObject.getExtensions() != null )
+        {
+            getExtensions( buf, schemaObject.getExtensions() );
+        }
+
+        buf.append( " ) " );
+
         return buf.toString();
     }
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java Wed Jan  6 17:52:15 2010
@@ -20,8 +20,15 @@
 package org.apache.directory.shared.ldap.schema;
 
 
+import java.util.List;
+
 import javax.naming.NamingException;
-import java.util.Comparator;
+
+import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.schema.comparators.ComparableComparator;
+import org.apache.directory.shared.ldap.schema.normalizers.NoOpNormalizer;
+import org.apache.directory.shared.ldap.schema.registries.Registries;
 
 
 /**
@@ -75,36 +82,386 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public interface MatchingRule extends SchemaObject
+public class MatchingRule extends AbstractSchemaObject
 {
+    /** The serialVersionUID */
+    private static final long serialVersionUID = 1L;
+
+    /** The associated Comparator */
+    protected LdapComparator<? super Object> ldapComparator;
+
+    /** The associated Normalizer */
+    protected Normalizer normalizer;
+
+    /** The associated LdapSyntax */
+    protected LdapSyntax ldapSyntax;
+
+    /** The associated LdapSyntax OID */
+    private String ldapSyntaxOid;
+
+
+    /**
+     * Creates a new instance of MatchingRule.
+     *
+     * @param oid The MatchingRule OID
+     * @param registries The Registries reference
+     */
+    public MatchingRule( String oid )
+    {
+        super( SchemaObjectType.MATCHING_RULE, oid );
+    }
+
+
     /**
-     * Gets the SyntaxImpl used by this MatchingRule.
+     * Inject the MatchingRule into the registries, updating the references to
+     * other SchemaObject
+     *
+     * @param registries The Registries
+     * @exception If the addition failed
+     */
+    public void addToRegistries( List<Throwable> errors, Registries registries ) throws NamingException
+    {
+        if ( registries != null )
+        {
+            try
+            {
+                // Gets the associated Comparator 
+                ldapComparator = ( LdapComparator<? super Object> ) registries.getComparatorRegistry().lookup( oid );
+            }
+            catch ( NamingException ne )
+            {
+                // Default to a catch all comparator
+                ldapComparator = new ComparableComparator( oid );
+            }
+
+            try
+            {
+                // Gets the associated Normalizer
+                normalizer = registries.getNormalizerRegistry().lookup( oid );
+            }
+            catch ( NamingException ne )
+            {
+                // Default to the NoOp normalizer
+                normalizer = new NoOpNormalizer( oid );
+            }
+
+            try
+            {
+                // Get the associated LdapSyntax
+                ldapSyntax = registries.getLdapSyntaxRegistry().lookup( ldapSyntaxOid );
+            }
+            catch ( NamingException ne )
+            {
+                // The Syntax is a mandatory element, it must exist.
+                throw new LdapSchemaViolationException(
+                    "The created MatchingRule must refers to an existing SYNTAX element",
+                    ResultCodeEnum.UNWILLING_TO_PERFORM );
+            }
+
+            /**
+             * Add the MR references (using and usedBy) : 
+             * MR -> C
+             * MR -> N
+             * MR -> S
+             */
+            if ( ldapComparator != null )
+            {
+                registries.addReference( this, ldapComparator );
+            }
+
+            if ( normalizer != null )
+            {
+                registries.addReference( this, normalizer );
+            }
+
+            if ( ldapSyntax != null )
+            {
+                registries.addReference( this, ldapSyntax );
+            }
+
+        }
+    }
+
+
+    /**
+     * Remove the MatchingRule from the registries, updating the references to
+     * other SchemaObject.
      * 
-     * @return the SyntaxImpl of this MatchingRule
-     * @throws NamingException
-     *             if there is a failure resolving the object
+     * If one of the referenced SchemaObject does not exist (), 
+     * an exception is thrown.
+     *
+     * @param registries The Registries
+     * @exception If the MatchingRule is not valid 
      */
-    Syntax getSyntax() throws NamingException;
+    public void removeFromRegistries( List<Throwable> errors, Registries registries ) throws NamingException
+    {
+        if ( registries != null )
+        {
+            /**
+             * Remove the MR references (using and usedBy) : 
+             * MR -> C
+             * MR -> N
+             * MR -> S
+             */
+            if ( ldapComparator != null )
+            {
+                registries.delReference( this, ldapComparator );
+            }
+
+            if ( ldapSyntax != null )
+            {
+                registries.delReference( this, ldapSyntax );
+            }
+
+            if ( normalizer != null )
+            {
+                registries.delReference( this, normalizer );
+            }
+        }
+    }
+
+
+    /**
+     * Gets the LdapSyntax used by this MatchingRule.
+     * 
+     * @return the LdapSyntax of this MatchingRule
+     */
+    public LdapSyntax getSyntax()
+    {
+        return ldapSyntax;
+    }
+
+
+    /**
+     * Gets the LdapSyntax OID used by this MatchingRule.
+     * 
+     * @return the LdapSyntax of this MatchingRule
+     * @throws NamingException if there is a failure resolving the object
+     */
+    public String getSyntaxOid()
+    {
+        return ldapSyntaxOid;
+    }
 
 
     /**
-     * Gets the Comparator enabling the use of this MatchingRule for ORDERING
+     * Sets the Syntax's OID
+     *
+     * @param oid The Syntax's OID
+     */
+    public void setSyntaxOid( String oid )
+    {
+        if ( !isReadOnly )
+        {
+            this.ldapSyntaxOid = oid;
+        }
+    }
+
+
+    /**
+     * Sets the Syntax
+     *
+     * @param oid The Syntax
+     */
+    public void setSyntax( LdapSyntax ldapSyntax )
+    {
+        if ( !isReadOnly )
+        {
+            this.ldapSyntax = ldapSyntax;
+            this.ldapSyntaxOid = ldapSyntax.getOid();
+        }
+    }
+
+
+    /**
+     * Update the associated Syntax, even if the SchemaObject is readOnly
+     *
+     * @param oid The Syntax
+     */
+    public void updateSyntax( LdapSyntax ldapSyntax )
+    {
+        this.ldapSyntax = ldapSyntax;
+        this.ldapSyntaxOid = ldapSyntax.getOid();
+    }
+
+
+    /**
+     * Gets the LdapComparator enabling the use of this MatchingRule for ORDERING
      * and sorted indexing.
      * 
-     * @return the ordering Comparator
-     * @throws NamingException
-     *             if there is a failure resolving the object
+     * @return the ordering LdapComparator
+     * @throws NamingException if there is a failure resolving the object
+     */
+    public LdapComparator<? super Object> getLdapComparator()
+    {
+        return ldapComparator;
+    }
+
+
+    /**
+     * Sets the LdapComparator
+     *
+     * @param oid The LdapComparator
      */
-    Comparator getComparator() throws NamingException;
+    public void setLdapComparator( LdapComparator<?> ldapComparator )
+    {
+        if ( !isReadOnly )
+        {
+            this.ldapComparator = ( LdapComparator<? super Object> ) ldapComparator;
+        }
+    }
+
+
+    /**
+     * Update the associated Comparator, even if the SchemaObject is readOnly
+     *
+     * @param oid The LdapComparator
+     */
+    public void updateLdapComparator( LdapComparator<?> ldapComparator )
+    {
+        this.ldapComparator = ( LdapComparator<? super Object> ) ldapComparator;
+    }
 
 
     /**
      * Gets the Normalizer enabling the use of this MatchingRule for EQUALITY
      * matching and indexing.
      * 
-     * @return the ordering Comparator
-     * @throws NamingException
-     *             if there is a failure resolving the object
+     * @return the associated normalizer
+     * @throws NamingException if there is a failure resolving the object
+     */
+    public Normalizer getNormalizer()
+    {
+        return normalizer;
+    }
+
+
+    /**
+     * Sets the Normalizer
+     *
+     * @param oid The Normalizer
+     */
+    public void setNormalizer( Normalizer normalizer )
+    {
+        if ( !isReadOnly )
+        {
+            this.normalizer = normalizer;
+        }
+    }
+
+
+    /**
+     * Update the associated Normalizer, even if the SchemaObject is readOnly
+     *
+     * @param oid The Normalizer
+     */
+    public void updateNormalizer( Normalizer normalizer )
+    {
+        this.normalizer = normalizer;
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        return objectType + " " + DescriptionUtils.getDescription( this );
+    }
+
+
+    /**
+     * Copy an MatchingRule
+     */
+    public MatchingRule copy()
+    {
+        MatchingRule copy = new MatchingRule( oid );
+
+        // Copy the SchemaObject common data
+        copy.copy( this );
+
+        // All the references to other Registries object are set to null.
+        copy.ldapComparator = null;
+        copy.ldapSyntax = null;
+        copy.normalizer = null;
+
+        // Copy the syntax OID
+        copy.ldapSyntaxOid = ldapSyntaxOid;
+
+        return copy;
+    }
+
+
+    /**
+     * @see Object#equals()
      */
-    Normalizer getNormalizer() throws NamingException;
+    public boolean equals( Object o )
+    {
+        if ( !super.equals( o ) )
+        {
+            return false;
+        }
+
+        if ( !( o instanceof MatchingRule ) )
+        {
+            return false;
+        }
+
+        MatchingRule that = ( MatchingRule ) o;
+
+        // Check the Comparator
+        if ( ldapComparator != null )
+        {
+            if ( !ldapComparator.equals( that.ldapComparator ) )
+            {
+                return false;
+            }
+        }
+        else
+        {
+            if ( that.ldapComparator != null )
+            {
+                return false;
+            }
+        }
+
+        // Check the Normalizer
+        if ( normalizer != null )
+        {
+            if ( !normalizer.equals( that.normalizer ) )
+            {
+                return false;
+            }
+        }
+        else
+        {
+            if ( that.normalizer != null )
+            {
+                return false;
+            }
+        }
+
+        // Check the Syntax
+        if ( !compareOid( ldapSyntaxOid, that.ldapSyntaxOid ) )
+        {
+            return false;
+        }
+
+        return ldapSyntax.equals( that.ldapSyntax );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void clear()
+    {
+        // Clear the common elements
+        super.clear();
+
+        // Clear the references
+        ldapComparator = null;
+        ldapSyntax = null;
+        normalizer = null;
+    }
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRuleUse.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRuleUse.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRuleUse.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRuleUse.java Wed Jan  6 17:52:15 2010
@@ -20,8 +20,14 @@
 package org.apache.directory.shared.ldap.schema;
 
 
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.naming.NamingException;
 
+import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.schema.registries.Registries;
+
 
 /**
  * Represents an LDAP MatchingRuleUseDescription defined in RFC 2252.
@@ -79,25 +85,212 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public interface MatchingRuleUse extends SchemaObject
+public class MatchingRuleUse extends AbstractSchemaObject
 {
+    /** The serialVersionUID */
+    private static final long serialVersionUID = 1L;
+
+    /** The list of attributes types OID the matching rule applies to */
+    private List<String> applicableAttributeOids;
+
+    /** The list of attributes types the matching rule applies to */
+    private List<AttributeType> applicableAttributes;
+
+
+    /**
+     * Creates a new instance of MatchingRuleUseDescription
+     */
+    public MatchingRuleUse( String oid )
+    {
+        super( SchemaObjectType.MATCHING_RULE_USE, oid );
+
+        applicableAttributeOids = new ArrayList<String>();
+        applicableAttributes = new ArrayList<AttributeType>();
+    }
+
+
+    /**
+     * Inject the MatchingRuleUse into the registries, updating the references to
+     * other SchemaObject
+     *
+     * @param registries The Registries
+     * @exception If the addition failed
+     */
+    public void addToRegistries( Registries registries ) throws NamingException
+    {
+        if ( registries != null )
+        {
+            AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
+
+            if ( applicableAttributeOids != null )
+            {
+                applicableAttributes = new ArrayList<AttributeType>( applicableAttributeOids.size() );
+
+                for ( String oid : applicableAttributeOids )
+                {
+                    applicableAttributes.add( atRegistry.lookup( oid ) );
+                }
+            }
+        }
+    }
+
+
+    /**
+     * @return The matchingRule's list of AttributeType OIDs the MRU applies to
+     */
+    public List<String> getApplicableAttributeOids()
+    {
+        return applicableAttributeOids;
+    }
+
+
+    /**
+     * @return The matchingRule's list of AttributeType OIDs the MRU applies to
+     */
+    public List<AttributeType> getApplicableAttributes()
+    {
+        return applicableAttributes;
+    }
+
+
+    /**
+     * Set the matchingRule's AttributeType OIDs the MRU applies to.
+     *
+     * @param applicableAttributes The AttributeType OIDs list
+     */
+    public void setApplicableAttributeOids( List<String> applicableAttributeOids )
+    {
+        if ( !isReadOnly )
+        {
+            this.applicableAttributeOids = applicableAttributeOids;
+        }
+    }
+
+
+    /**
+     * Set the matchingRule's AttributeType the MRU applies to.
+     *
+     * @param applicableAttributes The AttributeType list
+     */
+    public void setApplicableAttributes( List<AttributeType> applicableAttributes )
+    {
+        if ( !isReadOnly )
+        {
+            this.applicableAttributes = applicableAttributes;
+
+            // update the OIDS now
+            applicableAttributeOids.clear();
+
+            for ( AttributeType at : applicableAttributes )
+            {
+                applicableAttributeOids.add( at.getOid() );
+            }
+        }
+    }
+
+
+    /**
+     * Add a matchingRule's AttributeType OIDs the MRU applies to.
+     *
+     * @param oid A matchingRule's AttributeType OIDs the MRU applies to
+     */
+    public void addApplicableAttributeOids( String oid )
+    {
+        if ( !isReadOnly )
+        {
+            if ( !applicableAttributeOids.contains( oid ) )
+            {
+                applicableAttributeOids.add( oid );
+            }
+        }
+    }
+
+
+    /**
+     * Add a matchingRule's AttributeType the MRU applies to.
+     *
+     * @param oid A matchingRule's AttributeType the MRU applies to
+     */
+    public void addApplicableAttribute( AttributeType attributeType )
+    {
+        if ( !isReadOnly )
+        {
+            if ( !applicableAttributeOids.contains( attributeType.getOid() ) )
+            {
+                applicableAttributes.add( attributeType );
+                applicableAttributeOids.add( attributeType.getOid() );
+            }
+        }
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        return objectType + " " + DescriptionUtils.getDescription( this );
+    }
+
+
     /**
-     * Gets the matchingRule this MatchingRuleUse definition applies to.
-     * 
-     * @return the matchingRule
-     * @throws NamingException
-     *             if there is a failure resolving the object
+     * Copy an MatchingRuleUse
      */
-    public MatchingRule getMatchingRule() throws NamingException;
+    public MatchingRuleUse copy()
+    {
+        MatchingRuleUse copy = new MatchingRuleUse( oid );
+
+        // Copy the SchemaObject common data
+        copy.copy( this );
+
+        // Clone the APPLY AttributeTypes
+        copy.applicableAttributeOids = new ArrayList<String>();
+
+        // Copy the APPLIES oid list
+        for ( String oid : applicableAttributeOids )
+        {
+            copy.applicableAttributeOids.add( oid );
+        }
+
+        // Copy the APPLIES list (will be empty)
+        copy.applicableAttributes = new ArrayList<AttributeType>();
+
+        return copy;
+    }
 
 
     /**
-     * Gets the the attributes which can be used with the matching rule in an
-     * extensible match assertion.
-     * 
-     * @return the applicable attributes
-     * @throws NamingException
-     *             if there is a failure resolving the object
+     * @see Object#equals(Object)
      */
-    public AttributeType[] getApplicableAttributes() throws NamingException;
+    public boolean equals( Object o )
+    {
+        if ( !super.equals( o ) )
+        {
+            return false;
+        }
+
+        if ( !( o instanceof MatchingRuleUse ) )
+        {
+            return false;
+        }
+
+        MatchingRuleUse that = ( MatchingRuleUse ) o;
+
+        // TODO : complete the checks
+        return true;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void clear()
+    {
+        // Clear the common elements
+        super.clear();
+
+        // Clear the references
+        applicableAttributes.clear();
+        applicableAttributeOids.clear();
+    }
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/NameForm.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/NameForm.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/NameForm.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/NameForm.java Wed Jan  6 17:52:15 2010
@@ -20,8 +20,15 @@
 package org.apache.directory.shared.ldap.schema;
 
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
 import javax.naming.NamingException;
 
+import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.schema.registries.Registries;
+
 
 /**
  * A nameForm description. NameForms define the relationship between a
@@ -57,7 +64,7 @@
  *     NameFormDescription = LPAREN WSP
  *         numericoid                ; object identifier
  *         [ SP &quot;NAME&quot; SP qdescrs ]  ; short names (descriptors)
- *         [ SP &quot;DESC&quot; SP qdstring ] ; description
+ *         [ SP &quot;DESC&quot; SP qdstring ] ;String description
  *         [ SP &quot;OBSOLETE&quot; ]         ; not active
  *         SP &quot;OC&quot; SP oid            ; structural object class
  *         SP &quot;MUST&quot; SP oids         ; attribute types
@@ -80,7 +87,7 @@
  *   shall be different.
  * </pre>
  * 
- * @see <a href="http://www.faqs.org/rfcs/rfc2252.html">RFC2252 Section 6.22</a>
+ * @see <a href="http://www.faqs.org/rfcs/rfc225String2.html">RFC2252 Section 6.22</a>
  * @see <a
  *      href="http://www.ietf.org/internet-drafts/draft-ietf-ldapbis-models-11.txt">ldapbis
  *      [MODELS]</a>
@@ -88,17 +95,151 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public interface NameForm extends SchemaObject
+public class NameForm extends AbstractSchemaObject
 {
+    /** The serialVersionUID */
+    private static final long serialVersionUID = 1L;
+
+    /** The structural object class OID this rule applies to */
+    private String structuralObjectClassOid;
+
+    /** The structural object class this rule applies to */
+    private ObjectClass structuralObjectClass;
+
+    /** The set of required attribute OIDs for this name form */
+    private List<String> mustAttributeTypeOids;
+
+    /** The set of required AttributeTypes for this name form */
+    private List<AttributeType> mustAttributeTypes;
+
+    /** The set of allowed attribute OIDs for this name form */
+    private List<String> mayAttributeTypeOids;
+
+    /** The set of allowed AttributeTypes for this name form */
+    private List<AttributeType> mayAttributeTypes;
+
+
+    /**
+     * Creates a new instance of MatchingRule.
+     *
+     * @param oid The MatchingRule OID
+     * @param registries The Registries reference
+     */
+    public NameForm( String oid )
+    {
+        super( SchemaObjectType.NAME_FORM, oid );
+
+        mustAttributeTypeOids = new ArrayList<String>();
+        mayAttributeTypeOids = new ArrayList<String>();
+
+        mustAttributeTypes = new ArrayList<AttributeType>();
+        mayAttributeTypes = new ArrayList<AttributeType>();
+    }
+
+
+    /**
+     * Inject the NameForm into the registries, updating the references to
+     * other SchemaObject
+     *
+     * @param registries The Registries
+     */
+    public void addToRegistries( Registries registries ) throws NamingException
+    {
+        if ( registries != null )
+        {
+            AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
+
+            structuralObjectClass = registries.getObjectClassRegistry().lookup( structuralObjectClassOid );
+
+            if ( mayAttributeTypeOids != null )
+            {
+                mayAttributeTypes = new ArrayList<AttributeType>( mayAttributeTypeOids.size() );
+
+                for ( String oid : mayAttributeTypeOids )
+                {
+                    mayAttributeTypes.add( atRegistry.lookup( oid ) );
+                }
+            }
+
+            if ( mustAttributeTypeOids != null )
+            {
+                mustAttributeTypes = new ArrayList<AttributeType>( mustAttributeTypeOids.size() );
+
+                for ( String oid : mustAttributeTypeOids )
+                {
+                    mustAttributeTypes.add( atRegistry.lookup( oid ) );
+                }
+            }
+        }
+    }
+
+
+    /**
+     * Gets the STRUCTURAL ObjectClass this name form specifies naming
+     * attributes for.
+     * 
+     * @return the ObjectClass's oid this NameForm is for
+     */
+    public String getStructuralObjectClassOid()
+    {
+        return structuralObjectClassOid;
+    }
+
+
     /**
      * Gets the STRUCTURAL ObjectClass this name form specifies naming
      * attributes for.
      * 
      * @return the ObjectClass this NameForm is for
-     * @throws NamingException
-     *             if there is a failure resolving the object
+     * @throws NamingException If the structuralObjectClass is invalid
+     */
+    public ObjectClass getStructuralObjectClass() throws NamingException
+    {
+        return structuralObjectClass;
+    }
+
+
+    /**
+     * Sets the structural object class this rule applies to
+     * 
+     * @param structuralObjectClass the structural object class to set
+     */
+    public void setStructuralObjectClassOid( String structuralObjectClassOid )
+    {
+        if ( !isReadOnly )
+        {
+            this.structuralObjectClassOid = structuralObjectClassOid;
+        }
+    }
+
+
+    /**
+     * Sets the structural object class this rule applies to
+     * 
+     * @param structuralObjectClass the structural object class to set
+     */
+    public void setStructuralObjectClass( ObjectClass structuralObjectClass )
+    {
+        if ( !isReadOnly )
+        {
+            this.structuralObjectClass = structuralObjectClass;
+            this.structuralObjectClassOid = structuralObjectClass.getOid();
+        }
+    }
+
+
+    /**
+     * Gets all the AttributeTypes OIDs of the attributes this NameForm specifies as
+     * having to be used in the given objectClass for naming: as part of the
+     * Rdn.
+     * 
+     * @return the AttributeTypes OIDs of the must use attributes
+     * @throws NamingException if there is a failure resolving one AttributeTyoe
      */
-    ObjectClass getObjectClass() throws NamingException;
+    public List<String> getMustAttributeTypeOids() throws NamingException
+    {
+        return Collections.unmodifiableList( mustAttributeTypeOids );
+    }
 
 
     /**
@@ -107,10 +248,93 @@
      * Rdn.
      * 
      * @return the AttributeTypes of the must use attributes
-     * @throws NamingException
-     *             if there is a failure resolving the object
      */
-    AttributeType[] getMustUse() throws NamingException;
+    public List<AttributeType> getMustAttributeTypes()
+    {
+        return Collections.unmodifiableList( mustAttributeTypes );
+    }
+
+
+    /**
+     * Sets the list of required AttributeTypes OIDs
+     *
+     * @param mustAttributeTypeOids the list of required AttributeTypes OIDs
+     */
+    public void setMustAttributeTypeOids( List<String> mustAttributeTypeOids )
+    {
+        if ( !isReadOnly )
+        {
+            this.mustAttributeTypeOids = mustAttributeTypeOids;
+        }
+    }
+
+
+    /**
+     * Sets the list of required AttributeTypes
+     *
+     * @param mayAttributeTypes the list of required AttributeTypes
+     */
+    public void setMustAttributeTypes( List<AttributeType> mustAttributeTypes )
+    {
+        if ( !isReadOnly )
+        {
+            this.mustAttributeTypes = mustAttributeTypes;
+
+            // update the OIDS now
+            mustAttributeTypeOids.clear();
+
+            for ( AttributeType may : mustAttributeTypes )
+            {
+                mustAttributeTypeOids.add( may.getOid() );
+            }
+        }
+    }
+
+
+    /**
+     * Add a required AttributeType OID
+     *
+     * @param oid The attributeType OID
+     */
+    public void addMustAttributeTypeOids( String oid )
+    {
+        if ( !isReadOnly )
+        {
+            mustAttributeTypeOids.add( oid );
+        }
+    }
+
+
+    /**
+     * Add a required AttributeType
+     *
+     * @param attributeType The attributeType
+     */
+    public void addMustAttributeTypes( AttributeType attributeType )
+    {
+        if ( !isReadOnly )
+        {
+            if ( !mustAttributeTypeOids.contains( attributeType.getOid() ) )
+            {
+                mustAttributeTypes.add( attributeType );
+                mustAttributeTypeOids.add( attributeType.getOid() );
+            }
+        }
+    }
+
+
+    /**
+     * Gets all the AttributeTypes OIDs of the attribute this NameForm specifies as
+     * being usable without requirement in the given objectClass for naming: as
+     * part of the Rdn.
+     * 
+     * @return the AttributeTypes OIDs of the may use attributes
+     * @throws NamingException if there is a failure resolving one AttributeTyoe
+     */
+    public List<String> getMayAttributeTypeOids() throws NamingException
+    {
+        return Collections.unmodifiableList( mayAttributeTypeOids );
+    }
 
 
     /**
@@ -119,8 +343,167 @@
      * part of the Rdn.
      * 
      * @return the AttributeTypes of the may use attributes
-     * @throws NamingException
-     *             if there is a failure resolving the object
      */
-    AttributeType[] getMayUse() throws NamingException;
+    public List<AttributeType> getMayAttributeTypes()
+    {
+        return Collections.unmodifiableList( mayAttributeTypes );
+    }
+
+
+    /**
+     * Sets the list of allowed AttributeTypes
+     *
+     * @param mayAttributeTypeOids the list of allowed AttributeTypes
+     */
+    public void setMayAttributeTypeOids( List<String> mayAttributeTypeOids )
+    {
+        if ( !isReadOnly )
+        {
+            this.mayAttributeTypeOids = mayAttributeTypeOids;
+        }
+    }
+
+
+    /**
+     * Sets the list of allowed AttributeTypes
+     *
+     * @param mayAttributeTypes the list of allowed AttributeTypes
+     */
+    public void setMayAttributeTypes( List<AttributeType> mayAttributeTypes )
+    {
+        if ( !isReadOnly )
+        {
+            this.mayAttributeTypes = mayAttributeTypes;
+
+            // update the OIDS now
+            mayAttributeTypeOids.clear();
+
+            for ( AttributeType may : mayAttributeTypes )
+            {
+                mayAttributeTypeOids.add( may.getOid() );
+            }
+        }
+    }
+
+
+    /**
+     * Add an allowed AttributeType
+     *
+     * @param oid The attributeType oid
+     */
+    public void addMayAttributeTypeOids( String oid )
+    {
+        if ( !isReadOnly )
+        {
+            mayAttributeTypeOids.add( oid );
+        }
+    }
+
+
+    /**
+     * Add an allowed AttributeType
+     *
+     * @param attributeType The attributeType
+     */
+    public void addMayAttributeTypes( AttributeType attributeType )
+    {
+        if ( !isReadOnly )
+        {
+            if ( !mayAttributeTypeOids.contains( attributeType.getOid() ) )
+            {
+                mayAttributeTypes.add( attributeType );
+                mayAttributeTypeOids.add( attributeType.getOid() );
+            }
+        }
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        return objectType + " " + DescriptionUtils.getDescription( this );
+    }
+
+
+    /**
+     * Copy a NameForm
+     */
+    public NameForm copy()
+    {
+        NameForm copy = new NameForm( oid );
+
+        // Copy the SchemaObject common data
+        copy.copy( this );
+
+        // Copy the MAY AttributeTypes OIDs
+        copy.mayAttributeTypeOids = new ArrayList<String>();
+
+        for ( String oid : mayAttributeTypeOids )
+        {
+            copy.mayAttributeTypeOids.add( oid );
+        }
+
+        // Copy the MAY AttributeTypes (will be empty)
+        copy.mayAttributeTypes = new ArrayList<AttributeType>();
+
+        // Copy the MUST AttributeTypes OIDs
+        copy.mustAttributeTypeOids = new ArrayList<String>();
+
+        for ( String oid : mustAttributeTypeOids )
+        {
+            copy.mustAttributeTypeOids.add( oid );
+        }
+
+        // Copy the MUST AttributeTypes ( will be empty )
+        copy.mustAttributeTypes = new ArrayList<AttributeType>();
+
+        // Copy the Structural ObjectClass OID
+        copy.structuralObjectClassOid = structuralObjectClassOid;
+
+        // All the references to other Registries object are set to null.
+        copy.structuralObjectClass = null;
+
+        return copy;
+    }
+
+
+    /**
+     * @see Object#equals(Object)
+     */
+    public boolean equals( Object o )
+    {
+        if ( !super.equals( o ) )
+        {
+            return false;
+        }
+
+        if ( !( o instanceof NameForm ) )
+        {
+            return false;
+        }
+
+        NameForm that = ( NameForm ) o;
+
+        // TODO : complete the checks
+        return true;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void clear()
+    {
+        // Clear the common elements
+        super.clear();
+
+        // Clear the references
+        mayAttributeTypes.clear();
+        mayAttributeTypeOids.clear();
+        mustAttributeTypes.clear();
+        mustAttributeTypeOids.clear();
+        structuralObjectClass = null;
+    }
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/Normalizer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/Normalizer.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/Normalizer.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/Normalizer.java Wed Jan  6 17:52:15 2010
@@ -20,8 +20,6 @@
 package org.apache.directory.shared.ldap.schema;
 
 
-import java.io.Serializable;
-
 import javax.naming.NamingException;
 
 import org.apache.directory.shared.ldap.entry.Value;
@@ -33,8 +31,34 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public interface Normalizer extends Serializable
+public abstract class Normalizer extends LoadableSchemaObject
 {
+    /** The serialversionUID */
+    private static final long serialVersionUID = 1L;
+
+
+    /**
+     * The Normalizer base constructor. We use it's MR OID to
+     * initialize the SchemaObject instance
+     * 
+     * @param oid The associated OID. It's the element's MR OID
+     */
+    protected Normalizer( String oid )
+    {
+        super( SchemaObjectType.NORMALIZER, oid );
+    }
+
+
+    /**
+     * Use this default constructor when the Normalizer must be instantiated
+     * before setting the OID.
+     */
+    protected Normalizer()
+    {
+        super( SchemaObjectType.NORMALIZER );
+    }
+
+
     /**
      * Gets the normalized value.
      * 
@@ -42,7 +66,8 @@
      * @return the normalized form for a value
      * @throws NamingException if an error results during normalization
      */
-    Value<?> normalize( Value<?> value ) throws NamingException;
+    public abstract Value<?> normalize( Value<?> value ) throws NamingException;
+
 
     /**
      * Gets the normalized value.
@@ -51,5 +76,40 @@
      * @return the normalized form for a value
      * @throws NamingException if an error results during normalization
      */
-    String normalize( String value ) throws NamingException;
+    public abstract String normalize( String value ) throws NamingException;
+
+
+    /**
+     * Store the SchemaManager in this instance. It may be necessary for some
+     * normalizer which needs to have access to the oidNormalizer Map.
+     *
+     * @param schemaManager the schemaManager to store
+     */
+    public void setSchemaManager( SchemaManager schemaManager )
+    {
+        // Do nothing (general case).
+    }
+
+
+    /**
+     * @see Object#equals()
+     */
+    public boolean equals( Object o )
+    {
+        if ( !super.equals( o ) )
+        {
+            return false;
+        }
+
+        return o instanceof Normalizer;
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        return objectType + " " + DescriptionUtils.getDescription( this );
+    }
 }